[resolved] Excluding sticky posts (2 posts)

  1. Bob Wagstaff
    Posted 2 years ago #

    I'm writing a magazine style theme with a homepage consisting of a "Featured Article" and then excerpts of the latest posts in two columns below the "Feature".

    I'm running two loops, the first one looking for a sticky post to treat as the feature, using this code inserted directly before my first loop:

    <?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>

    This works fine, except that the sticky post also appears as the top post in the second set of posts.

    I've tried using the following code before the second loop to exclude the sticky:

    <?php query_posts(array("post__not_in" =>get_option("sticky_posts")));?>

    and this does remove the sticky and works fine one the homepage. But if you follow the navigation at the bottom to look for older posts, it simply duplicates the posts found on the first page.

    What am I missing?

    My test site is here but I have removed the second piece of coding, so that I can work on the rest of the site.

  2. Bob Wagstaff
    Posted 2 years ago #

    Solved it myself

    For anyone with the same issue, I replaced the second line of code with:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    				$sticky = array(  "post__not_in" =>get_option("sticky_posts"),   'paged' => $paged );
    				query_posts($sticky); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic