Help With WP_Query and posts_per_page
-
Hi guys,
I’m trying to create custom blog template for my theme. And I want to show one post per page (it’s whole blog post template). The problem I have is that even ‘posts_per_page’ is set to 1 it still shows two posts on first page, the rest of it is fine. Any ideas how to solve this issue? Thanks.
So here is my code
$args = array(
‘post_type’ => ‘post’,
‘posts_per_page’ => 1,
‘paged’ => $paged,
‘category_name’ => $categories,
‘order’ => $order,
‘orderby’ => $orderBy,
);$query = new WP_Query($args);
if ( $query->have_posts() ) :
while ( $query->have_posts() ): $query->the_post();
// show post
the_title();
the_content();
endwhile;
endif;
wp_reset_postdata();
// pagination
if($query->max_num_pages > 1):
$tempQuery = $wp_query;
$wp_query = NULL;
$wp_query = $query;
$big = 999999999;
$args = array(
‘base’ => ‘%_%’,
‘format’ => ‘?paged=%#%’,
‘prev_text’ => “”,
‘next_text’ => “”,
);
?>
<nav class=”blog-navigation text-center”>
<?php echo paginate_links($args); ?>
</nav>
<?php
$wp_query = NULL;
$wp_query = $tempQuery;
endif;
- The topic ‘Help With WP_Query and posts_per_page’ is closed to new replies.