Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How to detect the last image in the list?
Hi!
Help me, please.
<txp:images category="partners" wraptag="ul" break="" class="logo-list clearfix" sort="id">
<txp:thumbnail wraptag="li" class="one-fifth" link="1" />
</txp:images>
but at last image i need class=“one-fifth column-last”.
<txp:if_last_image><txp:thumbnail wraptag="li" class="one-fifth column-last" link="1" /><txp:else /></txp:if_last_image>
dont work with error
Error tag: <txp:if_last_image> -> Textpattern Warning: tag does not exist in the processing of the form "partners" on the page "default"
In result I need
<ul class="logo-list clearfix">
<li class="one-fifth"><a href="#"><img src="/images/content/logo_list_01.png" alt="" /></a></li>
<li class="one-fifth"><a href="#"><img src="/images/content/logo_list_02.png" alt="" /></a></li>
<li class="one-fifth"><a href="#"><img src="/images/content/logo_list_03.png" alt="" /></a></li>
<li class="one-fifth"><a href="#"><img src="/images/content/logo_list_04.png" alt="" /></a></li>
<li class="one-fifth column-last"><a href="#"><img src="/images/content/logo_list_05.png" alt="" /></a></li>
</ul>
Offline
#2 2013-05-04 14:16:24
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: How to detect the last image in the list?
As you have to serve a CSS grid with a column-last
class, we don’t need to care for four and less images, hence we can restrict ourselves to using only core tags.
Anywhere above your txp:images tag you need to define a variable value of 1 by putting <txp:variable name="img-num" value="1" />
there. Below in the page you add to that value: immediately in your thumbnail tag, namely inside the class attribute:
<txp:images category="partners" wraptag="ul" break="" class="logo-list clearfix" sort="id">
<txp:thumbnail wraptag="li" class='one-fifth<txp:output_form name="img-counter" />' link="1" />
</txp:images>
I used an output_form tag here to keep the code readable. Note the single apostrophes around it.
Now create a form “img-counter”, type “misc”, and place the following code inside:
<txp:if_variable name="img-num" value="5"><txp:variable name="img-num" value="1" /> column-last</txp:if_variable>
<txp:if_variable name="img-num" value="4"><txp:variable name="img-num" value="5" /></txp:if_variable>
<txp:if_variable name="img-num" value="3"><txp:variable name="img-num" value="4" /></txp:if_variable>
<txp:if_variable name="img-num" value="2"><txp:variable name="img-num" value="3" /></txp:if_variable>
<txp:if_variable name="img-num" value="1"><txp:variable name="img-num" value="2" /></txp:if_variable>
This code is iterated over each time the txp:images tag is parsed and on each pass the value is raised, except for the first step/line. Note that the code advances from higher values to lower ones, but raises the value (if 4 –> 5). This way it prevents setting the value to the triggering “5” on each pass.
BTW: You’ll have to remove all the returns from the form’s code, they’d create lots of unnecessary white space in your HTML, they’re only good for reading here.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Offline
Re: How to detect the last image in the list?
Hi
why not using a simple Css to achieve what you want because you dont need to add a class to the last item to style it like you want.
.one-fifth:last-child
{
border-right: 0;
margin-right: 0;
}
Offline
Re: How to detect the last image in the list?
Great, guys! Thanks! I used Dragondz’s css solution, it’s simple and effective.
Offline