Reputation: 3243
I am trying to get working pagination in my WP_Query
.
After trying more then 2 hour, no way except stackoverflow :-D.
What is my problem
Older and newer pagination links are appreaing and when I click on them, then it take me to the correct url which is : /?paged=2
.
But post list did not change, same post on every page.
Here is my code
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array(
'cat' => $cat,
(($paged != '') ? 'paged =>'. $paged : ''),
'posts_per_page' => $post_to_show
);
print_r($args);
$the_query = new WP_Query($args);
while ($the_query->have_posts()) : $the_query->the_post();
//post template
endwhile;
if ( get_next_posts_link() || get_previous_posts_link() ) {
echo '<div class="wp-navigation clearfix">
<div class="alignleft">'.next_posts_link('« Older Entries').'</div>
<div class="alignright">'.previous_posts_link('Newer Entries »').'</div>
</div>';
}
wp_reset_query();
Upvotes: 1
Views: 861
Reputation: 5693
Your $args
array looks wrong. Also, $paged
will never be empty (because it always gets assigned the default value of 1), so your check is redundant.
There is nothing wrong with passing 1
as page number.
$args = array(
'cat' => $cat,
'paged' => $paged,
'posts_per_page' => $post_to_show
);
Upvotes: 1