WordPress.org

Ready to get started?Download WordPress

Forums

Single sticky within multiple loop (2 posts)

  1. jennybeaumont
    Member
    Posted 2 years ago #

    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!
    -jennyb

  2. jennybeaumont
    Member
    Posted 2 years ago #

    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.

    ideas??
    thnx,
    -jennyb

Topic Closed

This topic has been closed to new replies.

About this Topic