Mult. Loops showposts=1 conflicting with do_not_duplicate
-
I’ve got a pretty standard setup using multiple loops. The first shows the blog’s most recent post the second, third and fourth show recent posts from three categories.
Here’s my issue:
I want the categories to show the most recent post in that category but not to duplicate the most recent post overall.
I implemented do_not_duplicate and it works great except it conflicts with ‘showposts=1’ so whichever category holds the most recent overall post shows up blank instead of showing the second most recent post. I know I need some additional parameters to have the categories offset by 1 if the most recent post overlaps but am at a loss on how to code.
Here’s my current code:
<?php $featured_query = new WP_Query('showposts=1'); while ($featured_query->have_posts()) : $featured_query->the_post(); $do_not_duplicate[] = $post->ID ?> <!-- most recent post overall --> <?php endwhile; ?> <?php query_posts('category_name=red&showposts=1&offset=1'); ?> <?php while (have_posts()) : the_post(); ?> <?php if (in_array($post->ID, $do_not_duplicate)) continue; update_post_caches($posts); ?> <!-- most recent in red category --> <?php endwhile; ?> <?php rewind_posts(); ?> <?php query_posts('category_name=blue&showposts=1'); ?> <?php while (have_posts()) : the_post(); ?> <?php if (in_array($post->ID, $do_not_duplicate)) continue; update_post_caches($posts); ?> <!-- most recent in blue category --> <?php endwhile; ?> <?php rewind_posts(); ?> <?php query_posts('category_name=yellow&showposts=1'); ?> <?php while (have_posts()) : the_post(); ?> <?php if (in_array($post->ID, $do_not_duplicate)) continue; update_post_caches($posts); ?> <!-- most recent in yellow category --> <?php endwhile; ?>
Thanks for the help!
- The topic ‘Mult. Loops showposts=1 conflicting with do_not_duplicate’ is closed to new replies.