Controlling number of posts displayed on a category archive page

  • jmek66

    #7451

    I’m trying to display an archive page of all posts within a particular category at http://www.jmek.net/lq2013b/category/authors. However, only a single post from that category is appearing. I tried a snippet (below) from Prasanna that I found in another support post, but it isn’t working.

    Any other ideas?

    function number_of_posts_on_archive($query){
    if ($query->is_category) {
    $query->set('posts_per_page', 15);
    }
    return $query;
    }

    add_filter('pre_get_posts', 'number_of_posts_on_archive');
    Mod

    Kenneth John Odle

    #38235

    Try

    function number_of_posts_on_archive($query){
    if ($query->is_category ( 'authors' ) ) {
    $query->set('posts_per_page', 15);
    }
    return $query;
    }

    add_filter('pre_get_posts', 'number_of_posts_on_archive');

    jmek66

    #38236

    Unfortunately, still no joy. Just one post in the archive at http://www.jmek.net/lq2013b/category/authors.

    Admin

    Syahir Hakim

    #38237

    Try this:

    /**
    * Limit the posts per page for specific category archive
    */
    function my_archive_posts_per_page( $query ){
    if ( $query->is_archive() && $query->is_main_query() ) {
    if ( is_category( 'authors' ) ) {
    $query->set( 'posts_per_page', 3 );
    }
    }
    }
    add_action( 'pre_get_posts', 'my_archive_posts_per_page' );
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.