Support » Fixing WordPress » Single sticky within multiple loop

  • Hi folks,

    I’m trying to work out a solution so that, within a multiple loop that displays 1) a sticky, 2) a list of posts, 3) a second list of posts, only one sticky shows though more than one may be defined.

    This is my current code:

    $myposts = new WP_Query('posts_per_page=8');
      while ($myposts->have_posts()) : $myposts->the_post();
      $do_not_duplicate[] = $post->ID?>
    <?php if ( is_sticky() ) :  ?>
    //sticky stuff
    <?php else : ?>
    //first list of 7 posts
    <?php endif; ?>
    <?php endwhile; ?>
    <?php query_posts(array('post__not_in'=>$do_not_duplicate));
     if (have_posts()) : while (have_posts()) : the_post();
    //second list of posts

    I just saw @alchymyth code in this great post, which gets me close, but I can’t seem to work it out so that I both limit the number of stickies AND get my other posts to display without duplicates.

    Any ideas/help would be much appreciated!

Viewing 1 replies (of 1 total)
  • I should probably add that it is important that any stickies after the first one shouldn’t be ignored in the subsequent list of posts. So excluding stickies from that list is not an option. Somehow I just need to verify and avoid duplicates.


Viewing 1 replies (of 1 total)
  • The topic ‘Single sticky within multiple loop’ is closed to new replies.