WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. bourkela
    Member
    Posted 3 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
    Member
    Posted 3 years ago #

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

  3. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

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

    for alternative see:

    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

    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:
    http://pastebin.com/3cqwMYet
    (untested)

  4. bourkela
    Member
    Posted 2 years ago #

    This worked perfectly. Thanks so much, alchymyth!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.