Archived topic
Quantity of Posts Showing under Category Tab
1 reply · Started by Jeremy on January 11, 2021
Hi,
My I have buttons set up to allow the reader to navigate to a certain category.
I have noticed that for my blog page I can adjust the amount of posts that are shown before you have to click through to the next page. For the Category, if the button is selected, it goes to that page but only shows 10 posts [no additional pages to click through].
How do i change the number of posts shown and also 'next page' option.
Regards
Hi,
You can control the number of posts shown on the category archive pages specifically by adding this PHP snippet:
function category_archive_post_per_page( $query ) {
if ( !is_admin && $query->is_category() && $query->is_main_query() ) {
$query->set( 'posts_per_page', '6' );
$query->set( 'orderby', 'date' );
}
}
add_action( 'pre_get_posts', 'category_archive_post_per_page' );
Here's how to add PHP: https://docs.generatepress.com/article/adding-php/
You can change the post_per_page value from 6 to your preferred number of posts per page.
...also ‘next page’ option.
The previous, next and pages buttons should automatically render unless you're using a child theme template that doesn't have this.