I’m using the following to create a slide for a slideshow out of every two posts.
<?php $i = 0; $slideshow_query = new WP_Query("showposts=6&cat=10"); ?>
<div id="slideshow-posts">
<div class="newslide">
<?php while ($slideshow_query->have_posts()) : $slideshow_query->the_post(); $do_not_duplicate = $post->ID; $i++; ?>
//my content
<?php if ($i == 2) { ?></div> <div class="newslide"><?php $i = 0; } ?>
<?php endwhile; ?>
</div>
Problem is it creates a blank slide at the end – how would I get it to carry out creation of a news slide every two posts (or every even post) except for the last time an even post occurs?
thanks
The operator you’re likely looking for is called modulus or modulo and returns your the remainder of a division:
This operator comes in handy to identify even/odd rows in a loop when used with a divisor of 2:
Or in your case something like this:
In order to find out of you have reached the last post, you could compare
$i + 1(since we start counting from 0) with the full amount of items returned by your query (max 6 in your example). And then close the<div>if they match.UPDATE
I’ve extended the example above according to my comment. This isn’t tested, but I believe that’s how I remember it to work (the post count that is).