Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #297630

    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.

    #297664

    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

    #297801

    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

    #298201

    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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Number of posts on Archive pages’ is closed to new replies.