Home Forums Tutorials and Hints from Users Getting Different Numbers of Posts on Home & Author Pages

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #77130
    hkp
    Participant

    The WordPress setting Reading > “Blog pages show at most” only allows the same number of posts to be shown on the Author Pages, as on the Home Page.

    For convenience of readers, I wanted to triple the number of posts on all Author Pages, while keeping the size of the Home Page unchanged.

    So, I added this code to my Child functions.php

    // Change post counts on Home and Author pages
    
    add_action('pre_get_posts', 'custom_posts_per_page');
    
    function custom_posts_per_page($query) {
    if (is_home()) {
    $query->set('posts_per_page', 10); // Set number of posts for home page
    } elseif (is_author()) {
    $query->set('posts_per_page', 30); // Set number of posts for author pages
    }
    }

    Hope this can help someone else.

    #77131
    scrambler
    Moderator

    Thank you for sharing.

    FYI, If you create you home page using the weaver “Page with post” template.

    That will give you an option to set the maximum number of posts per page for that page

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.