How to do 3 Loops Without Repeating Posts???
-
I’m creating a category page that will display posts 3 different ways. All the posts are in the same category; it’s just that I want them displayed as follows:
Post Listing 1 (1 Post) – Feature Article for That Category.
Post Listing 2 (Next 6 Posts) – Past Feature Articles.
Post Listing 3 (Next 13 Posts) – Other posts in the category.
All three post listings will be displayed differently, and I have no problem with that part of it.
The problem is how do I prevent the posts from repeating in each of the post listings.
So far, this is what I have for code:
<div class="catfeature">
<?php
$categoryvariable=$cat;
$my_query = new WP_Query('cat=' . $categoryvariable. '&showposts=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<!-- do stuff ... -->
<?php endwhile; ?>
</div>
<!-- End Cat Feature ... -->
<div class="catrecentfeatures">
<h2>Recent Features</h2>
<?php
$categoryvariable=$cat;
$my_query = new WP_Query('cat=' . $categoryvariable. '&showposts=6');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<!-- do stuff ... -->
<?php endwhile; ?>
</div>
<!-- End Recent Features ... -->
<div class="catmorefeatures">
<h2>More Features</h2>
<?php
$categoryvariable=$cat;
$my_query = new WP_Query('cat=' . $categoryvariable. '&showposts=-1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<!-- do stuff ... -->
<?php endwhile; ?>
</div>
<!-- End More Features ... -->I realize I’m starting a new query each time, and I know that’s part of the problem. I tried to hack the code found on http://codex.ww.wp.xz.cn/The_Loop#Multiple_Loops_in_Action,
but that only covers 2 loops, and I still get a repeat in the 3rd loop.Any help would be much appreciated.
Best – Michael
The topic ‘How to do 3 Loops Without Repeating Posts???’ is closed to new replies.