How to query ‘posts_per_page’ to display a different blog posts index template?

You can control what template loads for any type of query via the Template Filters.

Here’s an example using home_template that checks if posts_per_page is equal to 1, and loads single.php in that case.

function wpd_home_template( $home_template="" ){
    if( get_option( 'posts_per_page' ) == 1 ){
        $home_template = locate_template( 'single.php', false );
    }
    return $home_template;
}
add_filter( 'home_template', 'wpd_home_template' );

Leave a Comment