Change Number of Posts On 1st Page of Paginated Homepage Archive Only

This PHP code sets the post per page only on the first page of the home page archive.

All other paginated pages like page 2,3,4 and so on will display the number of posts set in the Reading settings native to WordPress.

Using a code editor and FTP, simply copy and paste the following code to the end of your child themes functions file.


Comments

9 responses to “Change Number of Posts On 1st Page of Paginated Homepage Archive Only”

  1. Thank’s for a very fast answer 🙂

    1. Another question. How do the search question sort the search result. It doesn’t seem to be in date order?

  2. I got a code from you. Do not know in which tutorial. It helped me to increase the number of posts on the category pages. I wonder if it could be altered so that it changes the number of posts on all archive pages – that is category, date and tag – but NOT on the home page. Or perhaps a code per archivetype?
    This is the code I got from you:
    [code]
    /* Change the number of recipe items to be displayed
    add_action( ‘pre_get_posts’, ‘wpsites_category_limit_posts’ );
    function wpsites_category_limit_posts( $query ) {

    if( $query->is_main_query() && !is_admin() && is_date() ) {
    $query->set( ‘posts_per_page’, ’20’ );
    }

    }
    [/code]
    Something completely different: The notify me of follow-up comments by email on this page doesn’t seem to function for me.

    1. Brad Dalton Avatar
      Brad Dalton

      Add this code to your functions file and change the 1

      1. Great! Thanks!

        1. How would I write the same thing if I want a different number on the search page? Tried to change is_archive to is_search but that didn’t do it.

          1. Brad Dalton Avatar
            Brad Dalton

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.