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: 110
Website

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: 9,007
Website GitHub Mastodon Twitter

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 | hblack.art | EMAP | A Sea change | Toolkit of Care
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: 4,578
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: 9,007
Website GitHub Mastodon Twitter

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 | hblack.art | EMAP | A Sea change | Toolkit of Care
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: 110
Website

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: 4,578
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: 9,007
Website GitHub Mastodon Twitter

Re: Display single image from an article

Are you using textpattern to upload the images?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
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: 110
Website

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: 9,007
Website GitHub Mastodon Twitter

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 | hblack.art | EMAP | A Sea change | Toolkit of Care
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: 110
Website

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

#11 2020-04-07 20:09:25

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: Display single image from an article

code365 wrote #322541:

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

If you can see them correctly in Content › Images, then the solution above using <txp:image name='<txp:category />.jpg' /> should work. If your image is not a jpg, then replace the jpg with png, gif or whatever your image is.
If it’s still not showing, have a look at the source code in your browser and see what the link to the image shows in the source code. Compare that with the correct link to the working image and that may help you find what’s not working as intended.


TXP Builders – finely-crafted code, design and txp

Offline

#12 2020-04-08 04:44:57

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: Display single image from an article

code365 wrote #322538:

Anyway to show you a screenshot ?

Yes please! but also check Jakob’s post.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB