Trying to create a 'switching' blog template using home.php, controlled by 'Blog posts per page' setting in the admin area. If set to '1', it will show the single post template. Anything higher and it will display the archive template.
In detail:
The following code works, except for archive pagination (clicking older/newer posts changes the URL but displays first page content only).
<div id="primary" class="content-area">
<h2>Switching Blog Template</h2>
<?php // Get ppp for query
$ppp_val = get_option( 'posts_per_page' ); ?>
<?php
// Single post loop
$blogsingle_query = new WP_Query( $ppp_val <= 1 );
if($blogsingle_query->have_posts()) :
while($blogsingle_query->have_posts()) : $blogsingle_query->the_post();
get_template_part( 'parts/content', 'post' );
endwhile;
wp_reset_postdata();
the_post_navigation();
endif;
?>
<?php
// Multiple posts loop ( PAGINATION DOESN'T WORK )
$blogmulti_query = new WP_Query( $ppp_val > 1 );
if($blogmulti_query->have_posts()) :
while($blogmulti_query->have_posts()) : $blogmulti_query->the_post();
get_template_part( 'parts/content', 'archive' );
endwhile;
wp_reset_postdata();
the_posts_navigation();
endif;
?>
</div><!-- #primary -->
In comparison, this alternate method does not work but feels like it might be a better track to follow?
<div id="primary" class="content-area">
<h2>Switching Blog Template</h2>
<?php $ppp_val = get_option( 'posts_per_page' ); ?>
<?php
$args=array(
'posts_per_page' => $ppp_val, // Get number of posts value
'meta_query' = array(
array(
'key' => 'posts_per_page', // Use this to compare
'compare' => '>',
'value' => 1,
'type' => 'NUMERIC',
)
),
);
$switch_query = new WP_Query( $args );
?>
<?php
if($switch_query->have_posts()) :
while($switch_query->have_posts()) : $switch_query->the_post();
get_template_part( 'parts/content', 'archive' );
endwhile; else:
?>
<?php get_template_part( 'parts/content', 'post' ); ?>
<?php endif; ?>
</div><!-- #primary -->