Use More Than One Loop On A Page, Without Printing Duplicate Posts

Let’s start with the first loop. Nothing hard here: we’re just going to get the eight most recent posts using the showposts parameter. Open the index.php file, and paste the following code to output your “featured” posts:

  1. <?php
    query_posts('showposts=8');
    $ids = array();
    while (have_posts()) : the_post();
    $ids[] = get_the_ID();
    the_title();
    the_content();
    endwhile;
    ?>

    Once that’s done, it’s time to apply our second loop and get all posts, excepted the ones we have already outputted in the first loop:

    1. <?php
      query_posts(array('post__not_in' => $ids));
      while (have_posts()) : the_post();
      the_title();
      the_content();
      endwhile;
      ?>