Excluding featured posts from "posts_per_page" count (4 posts)

  1. bourkela
    Posted 5 years ago #

    This is beyond my WordPress/PHP knowledge. Thanks in advance for any help!

    On the home page, I have five featured posts, and then below that I'd like to display the first five posts from several different categories. The below code is working great, except that the featured posts count towards the "posts_per_page" number, so some categories have less than five posts displayed.

    Is there a way to exclude the featured posts from the "posts_per_page" number? Below is the code showing the featured posts and the first category. (I'm also styling the first post from each category differently from the next four posts; hence the $postCount.)

    <script src="http://pastebin.com/embed_js.php?i=cGbtrZTX"></script>

    Thanks again for any help.

  2. bourkela
    Posted 5 years ago #

    Oh, there's no embedding support. Here's the pastebin URL.

  3. Michael
    Forum Moderator
    Posted 5 years ago #

    it is caused by the way your code handles duplicate posts;

    for alternative see:


    Alternatively you can pass the entire $do_not_duplicate array to $wp_query and only entries that match your criteria will be returned:

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

    Note that instead a string, the query parameter was an associative array, with post__not_in option.

    this might be a way to integrate this method into your code:

  4. bourkela
    Posted 5 years ago #

    This worked perfectly. Thanks so much, alchymyth!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.