Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Display newest image in a category
Essentially, I want to do this:
<img src="images/[image].jpg" alt="[alt]"/>
<p class="info">
[Image description]
</p>
… where [image] is the newest image in a category. I know there are plugins to display the newest image in a category, but they’re part of gallery plugins (and always insist on turning the image into a link, or only show the thumb and not the whole image).
Is there an easy way to do this?
Offline
Re: Display newest image in a category
With a little help from wet_for_each_image this would be quite simple:
<txp:wet_for_each_image limit="1" category="mycategory" sort="date desc"><txp:image id="{id}" /></txp:wet_for_each_image>
More complicated image layouts can be accomplished by a mashup of wet_for_each_image
and upm_image
. Just have a look at the samples, you’ll get an impression of how to achieve what you want.
Offline
Re: Display newest image in a category
If I try using wet_for_each_image on its own, it works fine (thanks for the plugin, wet), but only offers a way to display the image and not the caption. So, I installed upm_image, and once again I can display the image fine. But the moment I try displaying the caption, things go awry.
This is what works:
<txp:wet_for_each_image limit="1" category="Home-page" sort="date desc">
<txp:upm_image image_id="{id}"/>
</txp:wet_for_each_image>
But then, to display the caption, I made this change:
<txp:wet_for_each_image limit="1" category="Home-page" sort="date desc">
<txp:upm_image image_id="{id}" form="img_caption" />
</txp:wet_for_each_image>
… and made a misc article named “img_caption” with this inside:
<p class="info">
<txp:upm_img_caption />
</p>
The result vomits all over my page:
An error occurred in the following tag: <txp:upm_image image_id="3" form="img_caption" /> -> Notice: Undefined variable: form_name on line 413
… and…
An error occurred in the following tag: <txp:upm_image image_id="3" form="img_caption" /> -> Textpattern Notice: Form not found: on line 1332
I double-checked the form name and everything looks okay. I tried changing the form type, too, trying both misc and article, but it doesn’t seem to make a difference.
Any thoughts? I’ll leave the error up for the next while.
Offline
Re: Display newest image in a category
I’m using upm_image 0.4.4, which works as expected. Judging from line numbers at which your error is thrown you are using some other version. Installing a fresh instance of upm_image might be worth a try.
Offline
Re: Display newest image in a category
I’m actually running version 0.5 of upm_image. I’d try 0.4.4, but I can’t seem to find any older versions of the plugin archived.
Offline
Re: Display newest image in a category
I actually use article_custom
on my homepage and my list pages .. it’s for a particular section “photos” but there is also a “category” aspect of the tag .. might do what you want it to do .. maybe
[home - most recent]
<txp:article_custom allowoverride="1" form="picture-form" limit="1" pgonly="0" section="photos" status="4" />
[inside - random image]
<txp:article_custom allowoverride="0" category="photos" limit="1" form="picture-rand-form" pgonly="0" sort="rand()" />
nuff-respec ::: dannyb
Offline
Re: Display newest image in a category
Here’s a tag trace:
<txp:wet_for_each_image limit="1" category="Home-page" sort="date desc">
[SQL (0.000274): select id from geeztxptxp_image as txp_image where 1=1 and category in ('Home-page') order by date desc limit 0,1]
<txp:upm_image image_id="3" form="img_caption" />
[SQL (0.000170): select * from geeztxptxp_image as txp_image where id = '3' limit 0, 1]
[SQL (0.000164): select Form from geeztxptxp_form as txp_form where name='']
</txp:wet_for_each_image>
That’s interesting. It’s not picking up the form name from the tag at all. Maybe Mary needs to take a look?
Offline
Re: Display newest image in a category
Why would article custom not work ?
nuff-respec ::: dannyb
Offline
#9 2006-12-21 20:38:58
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Display newest image in a category
Bug fix.
Last edited by Mary (2013-01-24 17:19:08)
Offline
Re: Display newest image in a category
With the bug fix, the form is displaying properly, but amusingly I’ve lost the image. I hadn’t changed a single line of code.
I’ve temporarily fixed it by changing the form to this:
<img src="<txp:upm_img_full_url />" alt="Home"/>
<p class="info">
<txp:upm_img_caption />
</p>
(As for article_custom, the site is for a client, and the way I need things set up doesn’t make article_custom an option. That would have worked, though.)
Offline
#11 2006-12-22 03:52:52
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Display newest image in a category
…but amusingly I’ve lost the image.
You would, as that was all you had told it to display; when you use a form, it displays only exactly what you tell it to. :)
Offline
Re: Display newest image in a category
Ah, that would make sense, then. I had assumed that by specifying a form, it was going to output the same as the original tag with the form appended to the end. Not sure why I was thinking that, because this makes a lot more sense. :)
Thanks for your help, Mary and wet, and thanks for the plugins
Offline