Here is the code:
<?php if ( have_posts() ) : ?>
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('showposts=5'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query- >the_post();
?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php higher_content_nav( 'nav-below' ); ?>
<?php $wp_query = null; $wp_query = $temp;?>
<?php endif; ?>
How can I show posts per page not 5 but default? I mean post that we can set at back end at Reading Settings, Blog pages show at most – number of post.
The safest way is to call
get_option
, which gets the value directly from the database:Global variables like
$numposts
are not guaranteed to be set.For future reference, you can usually determine what to pass to
get_option
by finding thename
attribute of the setting’s<input>
in WP Admin.You are using
WP_Query()
, it does not have any default value for the number of posts per page.You should however note that
showposts
has been replaced byposts_per_page
in your code:Here is the solution: