Support » Fixing WordPress » Duplicate Posts in sidebar

  • nerdynothings


    I have two sidebars running custom loops on my index page.

    Is there a way for the sidebars not to repeat posts that are already listed within the main loop?

    $postslist = get_posts('category=8&numberposts=1&order=DESC&orderby=date&offset=2');
    foreach ($postslist as $post) :
    ***This is where the first post in the category goes, excerpt, title and image.
    <?php endforeach; ?>
    $postslist = get_posts('category=8&numberposts=4&order=DESC&orderby=date&offset=3');
    foreach ($postslist as $post) :
    setup_postdata($post); ?>
    ***This is where the titles for 4 more posts go.
    <?php endforeach; ?>

    I really hope that makes sense and you can help me.

Viewing 1 replies (of 1 total)
  • Michael


    Forum Moderator

    as luckily your main loop runs first, i could imagine collecting all post ids of the main loop into a gloabl array; and use this arry in the ‘post__not_in’ parameter of your sidebar queries.

    here is a bit of information:
    esp. under here ‘Note for Multiple Posts in the First Category ‘

    and this snippet:

    <?php query_posts(array('post__not_in'=>$do_not_duplicate));
     if (have_posts()) : while (have_posts()) : the_post();
     update_post_caches($posts); ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Duplicate Posts in sidebar’ is closed to new replies.