Hi,
I’m trying to find out how to change number of posts shown on Archive pages – grid layout
Is there any simple code to add it to functions.php of child theme?
Thanks.
Hi tomitos!
Please add following code to Functions.php file in Appearance > Editor
add_action( 'pre_get_posts', 'set_posts_per_page' );
function set_posts_per_page( $query ) {
global $wp_the_query;
if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_archive() ) ) {
$query->set( 'posts_per_page', 2 );
}
return $query;
}
and change 2 to neeeded number
Best regards,
Yigit
Hi Yigit
thanks for the tip. I added to the functions.php of my child theme and works well for number between 1 – 9, but not for more than 10, 20 for an example. Whan I change to 10+ (12, 14 …) it always displays 10 (as default in grid).
Tomaz
Hi
I remembered that I have to set number of post show on one site under WP-admin / Settings / Reading :)
So, you may tag this thread as Solved.
Thanks.