WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Change number of posts on category pages?

[Resolved] Change number of posts on category pages?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Michael Beckwith

    @tw2113

    We don’t actually control this type of thing. Our plugin is meant only to register the post types and taxonomies, not control any of the output from the content you create with the post types/taxonomies you register.

    That said, I believe by default it’s controlled by the “Posts per page” setting in your Settings > Reading area, but that is also a setting used by other parts of your website, so changing it would affect more than just your category archive.

    Best I have for your case is a bit technical, and I’m not sure about your comfort level with php.

    Combine the example from http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Changing_the_number_of_posts_per_page.2C_by_post_type with an if statement check for is_category() instead of the example’s is_post_type()

    Hi Michael,

    Thanks for the response. I’ve already tried Settings>Reading but has made no difference.

    I thought I might have to change something in PHP, but am hesitant to make any changes to PHP files. I would if I knew exactly what to do (or even which PHP file to edit!)

    If it’s a simple matter of injecting the code into a file, I’m sure I can handle that (I need to improve my understanding of PHP anyway).

    Can you give some slightly more specific instructions?

    Thanks!

    Plugin Author Michael Beckwith

    @tw2113

    function conditional_custom_category_limit( $query ) {
    
        if ( is_admin() || ! $query->is_main_query() )
            return;
    
        if ( is_category() ) {
            $query->set( 'posts_per_page', 1 );
        }
    }
    add_action( 'pre_get_posts', 'conditional_custom_category_limit' );

    set 1 to however many you want. This should go in your theme’s functions.php file. Do be careful editing that file, especially if you’re doing it through the WP Admin, as php errors can cause a white screen and you won’t be able to get back in until you get the error resolved via FTP or so.

    I inserted that and fortunately had no php errors/white screen but it doesn’t appear to have worked. Although I upped the number of posts to 200, it’s still only displaying 5.

    Would it have anything to do with the fact that my custom categories are labeled as ‘services’ instead of categories? E.g:

    http://movingbodyresources.com/services/martial-arts/

    Thanks again.

    Plugin Author Michael Beckwith

    @tw2113

    So you’re saying this is a custom taxonomy, and not the default made “Categories” ? That would actually play a part in this working.

    Sorry if I wasn’t clear about that, Michael. Yes, the ‘categories’ I’m talking about are actually custom taxonomies built using the Custom Post Types UI plugin. The one I’m particularly concerned with at the moment is ‘services’, as you can see in the URLs above.

    Plugin Author Michael Beckwith

    @tw2113

    try is_tax instead of is_category and pass in the taxonomy slug

    Tried changing is_category to is_tax but that didn’t work, so tried is_services & is_service instead but still no dice.

    What do you mean by ‘pass in the taxonomy slug’?

    Sorry–I’m a total PHP beginner!

    Plugin Author Michael Beckwith

    @tw2113

    if ( is_tax( 'service' ) ) {
        $query->set( 'posts_per_page', 1 );
    }

    May also be a case of doing $query->is_tax( 'service' ) if the first version doesn’t work. Worth tinkering with.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] Change number of posts on category pages?’ is closed to new replies.