Im using wordpress and using the following to get the last 3 most recent posts:
<?php query_posts('showposts='.$latest_num.'&cat=-'.$featured_cat.','.$latest_ignore.''); ?>
<?php while (have_posts()) : the_post(); ?>
<li>
<div class="imgholder">
<a href="/wp-content/themes/twentyten/images/slide1.jpg" data-gal="prettyPhoto[featured]" title="<?php the_title(); ?>">
<img src="<?php echo get_post_meta($post->ID, 'thumbnail',true) ?>" width="275" height="145" alt="Post Image" class="postimg-s" />
</a>
</div>
<h4><?php the_title(); ?></h4>
<p><?php the_content('Read more...'); ?></p>
</li>
<?php endwhile; ?>
What I want to do is add a class named 'last'
to the <li>
element on the 3rd interation through the loop.
Anyone got any ideas how I could add this?
Setup a counter outside your while loop
Check the modulus of that counter and output the class if required
Increment your counter before closing the loop:
Or, applied to your code:
The counter-intuitive look of the modulus condition is that whenever the counter is divisible by exactly 3 it will return 0.
Replace the line
with
Li should be li
Don’t forgot to initialize the $iCounterLi before the loop