If you have created a Featured posts section on your blog homepage, you probably have the problem of showing duplicate posts when running two distinct loops. In this recipe, you'll learn how to use two (or more) distinct loops while being sure not to get any duplicated posts.
Let's start with the first loop. Nothing difficult in this case, we're just going to get the latest eight posts by using the
showposts
parameter. Open theindex.php
and paste the following code to output your Featured posts:<?php query_posts('showposts=8'); $saved_ids = array(); while (have_posts()) : the_post(); $saved_ids[] = get_the_ID(); the_title(); the_content(); endwhile; ?>
Once complete, it's time to apply the second loop and get all posts, except the ones that we have already output in the first loop:
<?php query_posts(array('showposts' => 1, 'cat' => 3,'post__not_in' => $saved_ids...