Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-04-07 04:19:45

code365
Member
From: California
Registered: 2009-08-16
Posts: 69

Display single image from an article

I am not sure if I am doing this right. I tried several image tags but nothing seems to work. Can some please help me understand what I am doing wrong?

Thank you

<txp:category_list parent='<txp:section />' exclude='<txp:section />'  wraptag="div"  break="" class="row">
<div class="col-lg-4">
    <figure class="product-item">
        <txp:category title="0" link="1">
        <txp:article_image />
        <figcaption class="product-title">
            <txp:category title="1" link="0" />
        </figcaption>
         </txp:category  >
   </figure>
  </div>
</txp:category_list>

Last edited by code365 (2020-04-07 14:24:51)

Offline

#2 2020-04-07 05:44:02

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,905
Website

Re: Display single image from an article

Again, Let me see if I understand what you are trying to do. Please correct me if I am wrong.

You would like to have a series of images with their captions, each one linking to one particular image. If that is the case, I think that your code will not work as the category_list tag does just that, it looks for categories, not articles. One untested way I can think of to fetch the article_image from the latest article of a category is using:

<txp:category_list parent='<txp:section />' exclude='<txp:section />' wraptag="div" html_id="sidemenu" break="" class="row">
	<div class="col-lg-4">
		<txp:article_custom category='<txp:category />' break="" wraptag="" limit="1">
			<figure class="product-item">
				<txp:category title="0" link="1"><txp:article_image /></txp:category>
				<figcaption class="product-title">
					<txp:category title="1" link="0" />
				</figcaption>
			</figure>
		</txp:article_custom>
	</div>
</txp:category_list>

> Edited code

Last edited by colak (2020-04-07 06:24:44)


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#3 2020-04-07 06:31:29

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,810
Website

Re: Display single image from an article

And another way would be to name an image the same as your category name:

  • in Content > Images change the name of your image to category-name.jpg.
  • In your code use <txp:image name='<txp:category />.jpg' /> to output that image.

TXP Builders – finely-crafted code, design and txp

Offline

#4 2020-04-07 06:42:51

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,905
Website

Re: Display single image from an article

jakob wrote #322530:

And another way would be to name an image the same as your category name:

  • in Content > Images change the name of your image to category-name.jpg.
  • In your code use <txp:image name='<txp:category />.jpg' /> to output that image.

That is indeed a better idea! Here’s the code

<txp:category_list parent='<txp:section />' exclude='<txp:section />' wraptag="div" html_id="sidemenu" break="" class="row">
	<div class="col-lg-4">
		<figure class="product-item">
			<txp:category title="0" link="1"><txp:image name='<txp:category />.jpg' /></txp:category>
			<figcaption class="product-title">
				<txp:category title="1" link="0" />
			</figcaption>
		</figure>
	</div>
</txp:category_list>

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#5 2020-04-07 13:00:58

code365
Member
From: California
Registered: 2009-08-16
Posts: 69

Re: Display single image from an article

You guys are awesome.

I renamed the image to category-name but nothing display. Could it be because I have all the images inside a folder and not outside.

In the image folder I have five images but one them would be the main image.

Offline

#6 2020-04-07 15:41:14

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,810
Website

Re: Display single image from an article

code365 wrote #322534:

You guys are awesome.

I renamed the image to category-name but nothing display. Could it be because I have all the images inside a folder and not outside.

If you’re not using Textpattern’s image panel to manage your images, you can just do a regular html img tag pointing to the image file named the same as your category in place of the Textpattern txp:image tag, e.g.

<img src="/path/to/your/image-folder/<txp:category />.jpg" alt="<txp:category title />">

Add width/height attributes as you need them.


TXP Builders – finely-crafted code, design and txp

Offline

#7 2020-04-07 16:03:40

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,905
Website

Re: Display single image from an article

Are you using textpattern to upload the images?


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#8 2020-04-07 16:36:45

code365
Member
From: California
Registered: 2009-08-16
Posts: 69

Re: Display single image from an article

Yes, I am using the txp image uploader but I put image in folders.

Anyway to show you a screenshot ?

Last edited by code365 (2020-04-07 18:16:59)

Offline

#9 2020-04-07 17:03:00

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,905
Website

Re: Display single image from an article

code365 wrote #322538:

Yes, I am using the txp image uploader but I put image in folders.

So the images do not appear in the database and the txp interface right?


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#10 2020-04-07 18:15:19

code365
Member
From: California
Registered: 2009-08-16
Posts: 69

Re: Display single image from an article

It’s uploading to the database because I see it in the Content->Images->then the folder I created for the images.

Offline

Board footer

Powered by FluxBB