WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Duplicate posts

I'm trying to create a home page, in which there is a top posts section that displays the three most recent posts (for all categories), and category subsections that display the most recent posts for that category only.

I know how to get that far, but I'm not sure how to make sure there isn't any overlap (I don't want any posts to show up both at the top and in the category section of the page). Is there an efficient way to do this?

share|improve this question

marked as duplicate by Brian Fegter, kaiser, Rarst Oct 2 '12 at 21:09

This question was marked as an exact duplicate of an existing question.

Another: wordpress.stackexchange.com/questions/50677/… Please use the search feature before posting a question. :) – Brian Fegter Sep 14 '12 at 4:08
Sorry, I searched for a solution before, but didn't find this. Very similar question. Thx! – a_user Sep 14 '12 at 18:12
up vote 0 down vote accepted

Well, you're going to have a lot of loops and a lot of custom WP_Query objects.

To start, create an $all_posts variable before you start the main loop on your home page. You should likely put all this in your front-page.php template.

$all_posts = array();
while(have_posts()): the_post();
    $all_posts[] = $post->ID;
    // do stuff with the main loop here

On each subsequent loop, use the $all_posts variable to exclude posts that already happened. Say you want to create loops for the categories with the term_id's 1, 2, and 3:

foreach(array(1, 2, 3) as $cat))
    $cat_query = new WP_Query(array(
        'cat'   => $cat,
        'post__not_in' => $all_posts,
            $all_posts[] = $post->ID;
            // display stuff here

Just keep appending post IDs to the $all_posts variable to make sure subsequent queries don't include posts that were already seen.

share|improve this answer
I had forgotten about the 'post__not_in' parameter. This is what I'm looking for. Thanks! – a_user Sep 14 '12 at 18:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.