4 deleted 149 characters in body
source | link

Long time listener, first time caller! I have a puzzle that I'm one piece away from solving that needs someone wiser than me:

At a glance:

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 -->

Thanks in advance for any pointers you can give - tearing my hair out here!

Adam

Long time listener, first time caller! I have a puzzle that I'm one piece away from solving that needs someone wiser than me:

At a glance:

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 -->

Thanks in advance for any pointers you can give - tearing my hair out here!

Adam

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 -->
3 Improved formatting, and corrected args in second example
source | link

Long time listener, first time caller! I have a puzzle that I'm one piece away from solving that needs someone wiser than me:

At a glance:

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$args=array(
 = array('posts_per_page' => $ppp_val, // Get number of posts value
  'meta_query'=>'meta_query' = array(
    array(
      'key' => 'posts_per_page', // Use this to compare
      'compare' => '>',
      'value' => 1,
      'type' => 'numeric''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 -->

Thanks in advance for any pointers you can give - tearing my hair out here!

Adam

Long time listener, first time caller! I have a puzzle that I'm one piece away from solving that needs someone wiser than me:

At a glance:

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(
  'meta_query'=> array(
    array(
      'key' => 'posts_per_page',
      '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 -->

Thanks in advance for any pointers you can give - tearing my hair out here!

Adam

Long time listener, first time caller! I have a puzzle that I'm one piece away from solving that needs someone wiser than me:

At a glance:

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 -->

Thanks in advance for any pointers you can give - tearing my hair out here!

Adam

2 Amended formatting, and corrected post navigation in first example
source | link

Long time listener, first time caller! I have a puzzle that I'm one piece away from solving that needs someone wiser than me:

At a glance:

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>Smart<h2>Switching NewsBlog 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(
  'meta_query'=> array(
    array(
      'key' => 'posts_per_page',
      '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 -->

Thanks in advance for any pointers you can give - tearing my hair out here!

Adam

Long time listener, first time caller! I have a puzzle that I'm one piece away from solving that needs someone wiser than me:

At a glance:

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>Smart News 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 );
while($blogsingle_query->have_posts()) : $blogsingle_query->the_post();
get_template_part( 'parts/content', 'post' );
endwhile;
wp_reset_postdata();
?>

<?php
// Multiple posts loop ( PAGINATION DOESN'T WORK )

$blogmulti_query = new WP_Query( $ppp_val > 1 ); 
while($blogmulti_query->have_posts()) : $blogmulti_query->the_post();
get_template_part( 'parts/content', 'archive' );
endwhile;
wp_reset_postdata(); 
the_posts_navigation();
?>


</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(
  'meta_query'=> array(
    array(
      'key' => 'posts_per_page',
      '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 -->

Thanks in advance for any pointers you can give - tearing my hair out here!

Adam

Long time listener, first time caller! I have a puzzle that I'm one piece away from solving that needs someone wiser than me:

At a glance:

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(
  'meta_query'=> array(
    array(
      'key' => 'posts_per_page',
      '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 -->

Thanks in advance for any pointers you can give - tearing my hair out here!

Adam

1
source | link