Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Can <txp:images> remain unsorted?
Hi All, I would like to output images based on an article’s Article Image field using <txp:images />
like so:
<ul class="thumbnails clearfix">
<txp:images break="">
<li><a href="<txp:image_url />" class="<txp:image_info type="w" />x<txp:image_info type="h" />"><txp:thumbnail /></a></li>
</txp:images>
This is in an <txp:article />
context. The thing is, I’ve listed the image ID’s in the exact order I want them output, but <txp:images />
sorts them. Is there any way I can leave them unsorted, preserving the order I’ve specified?
Thanks.
Offline
Re: Can <txp:images> remain unsorted?
Oops! Nevermind. I guess I’d like to be able to do this with native txp tags, but the excellent soo_image does the job.
Offline
#3 2011-03-03 17:17:46
- redbot
- Plugin Author
- Registered: 2006-02-14
- Posts: 1,410
Re: Can <txp:images> remain unsorted?
nabrown78 wrote:
… This is in an
<txp:article />
context. The thing is, I’ve listed the image ID’s in the exact order I want them output, but<txp:images />
sorts them. Is there any way I can leave them unsorted, preserving the order I’ve specified?
I use this method, seems a little hacky but it is not really:
<txp:images id='<txp:custom_field name="article_image" />' wraptag="ul" break="li" sort=' field(id, <txp:custom_field name=''article_image'' />)'>
Edit: Er… too late
Last edited by redbot (2011-03-03 17:37:31)
Offline
Re: Can <txp:images> remain unsorted?
Aha! Well, that would do the job without a plugin. Thanks for the help redbot!
Offline
#5 2011-03-03 17:43:05
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: Can <txp:images> remain unsorted?
redbot wrote:
<txp:images id='<txp:custom_field name="article_image" />' wraptag="ul" break="li" sort=' field(id, <txp:custom_field name=''article_image'' />)'>
Thaaat’s cool! I was struggling with this some weeks ago and didn’t think of the SQL-sorting method. Thanks, Luca! :)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#6 2011-03-04 01:08:00
- redbot
- Plugin Author
- Registered: 2006-02-14
- Posts: 1,410
Re: Can <txp:images> remain unsorted?
uli wrote:
…Thaaat’s cool! I was struggling with this some weeks ago and didn’t think of the SQL-sorting method. Thanks, Luca! :)
You are welcome Uli.
BTW, we have to thank Bloke for the clever txp:custom_field name="article_image"
trick.
Last edited by redbot (2011-03-04 01:17:46)
Offline
Re: Can <txp:images> remain unsorted?
Time out — does that mean that <txp:custom_field name="article_image" />
outputs what is actually in the article image field (that would be interesting)? Or do you have to create an actual custom field called that?
Offline
Re: Can <txp:images> remain unsorted?
Nora, I just posted a new TXP Tip on how to display the first image from a list in the article image field to help answer your question.
As redbot indicates, the trick is courtesy of the ever wonderful Stef Dawson.
Offline
#9 2011-03-04 15:07:30
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: Can <txp:images> remain unsorted?
nabrown78 wrote:
Or do you have to create an actual custom field called that?
No, that’s not necessary. BTW, Textpattern outputs a lot more data fields if they’re queried by a custom_field/if_custom_field tag.
Last edited by uli (2011-03-04 15:08:40)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Can <txp:images> remain unsorted?
jstubbs wrote:
Nora, I just posted a new TXP Tip on how to display the first image from a list in the article image field to help answer your question.
Very cool — I left a comment, with a questions, on that page (and actually, if it’s not too much of a PITA, can you edit my url to be www.norabrowndesign.com, instead I have a comma in there somehow).
Offline
#11 2011-03-04 15:52:58
- redbot
- Plugin Author
- Registered: 2006-02-14
- Posts: 1,410
Re: Can <txp:images> remain unsorted?
nabrown78 wrote:
Time out — does that mean that
<txp:custom_field name="article_image" />
outputs what is actually in the article image field (that would be interesting)? Or do you have to create an actual custom field called that?
uli wrote:
No, that’s not necessary. BTW, Textpattern outputs a lot more data fields if they’re queried by a custom_field/if_custom_field tag.
Yes, Uli is right. That’t because if you examine the “custom_field” function as defined in taghandlers.php you’ll realize that any value you pass it as the tag attribute ‘name’ will be then used to fetch a specific raw value from the $thisarticle
array.
In other words <txp:custom_field name = "article_image" />
is quite the same that
<txp:php>
echo $thisarticle['article_image'];
</txp:php>
In the same vein if you write:
<txp:custom_field name = "authorid" />
You should get the author of the currently viewed article.
I hope it’s clear enough.
Offline
Re: Can <txp:images> remain unsorted?
redbot wrote:
if you examine the “custom_field” function… any value you pass it as the tag attribute ‘name’ will be then used to fetch a specific raw value from the
$thisarticle
array.
This is verging on a ‘bug’ insofar as the function name implies that you should only be able to retrieve custom field data, but as redbot says you can actually get any article field.
Most of $thisarticle
is queryable using dedicated tags, but <txp:article_image />
is the exception because it formats the data before output. So this trick is actually pretty handy and I’d be loathe to lose it because it fills a gap in the function suite. Maybe if the article_image tag is modded one day to allow it to output its raw value then this loophole can be closed. But not before: it’s too useful!
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline