In WordPress, I’m using this:
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
echo "<div class='test'>test</div>";
<?php endwhile; ?>
I’d now like it so for every 2nd element, it would add the “last” class to the div, so the final code could be:
<div class='test'>test</div>
<div class='test last'>test</div>
<div class='test'>test</div>
<div class='test last'>test</div>
<div class='test'>test</div>
<div class='test last'>test</div>.....
Many thanks for any pointers.
You can also use WordPress’ built-in post count field, $wp_query->current_post