I have the following code:
$attr = array(
'align' => 'left',
'class' => 'thumbnail imageRight',
'width' => 350,
'height' => 350
);
$post_query = array ( 'post_type' => 'post' );
$posts = new WP_Query ( $post_query );
if($posts->have_posts()){
while($posts->have_posts()){
$posts->the_post();
?>
<div class="post">
<?php the_post_thumbnail('medium', $attr); ?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<p><?php the_excerpt(); ?></p>
</div>
<?php
}
next_posts_link('« Older Entries');
previous_posts_link('Newer Entries »');
}
Which can be seen in action here. This page displays currently 3 of the 21 posts in the database. How ever there is no pagination.
Can some one tell me why?
Both
next_posts_link
andprevious_posts_link
use the global$wp_query
and$paged
. You have to chase function calls around the source code to see that (but it is pretty obvious withnext_post_links
). They don’t work with custom queries but I believe you can cheat.Try that.
There is a related thread wordpress.stackexchange.com.
https://wordpress.stackexchange.com/questions/77661/next-posts-link-works-only-with-original-wp-query/77666#77666