Duplicate Posts in sidebar (2 posts)

  1. nerdynothings
    Posted 5 years ago #

    I have two sidebars running custom loops on my index page. http://nerdynothings.com

    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.

  2. Michael
    Part-Time Forum Moderator
    Posted 5 years ago #

    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); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic