I just can't seem to get pagination in Wordpress to work... I have tried for weeks to get it going but it seems to be impossible :(. Is it doable, in that case how?
this is my Wp_Query:
$all_posts = new WP_Query(array(
'posts_per_page' => 3,
));
And this is how I output it:
if ($all_posts->have_posts()): while ($all_posts->have_posts()) : $all_posts->the_post();
// content rendered here
<?php endwhile; ?>
<?php endif; ?>
For normal pagination at it's most basic level:
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
You can use one of these plugins to add numbered pagination functionality. As of now, this isn't supported natively in WordPress. That would be a good reference point to start with if you're trying to write it from scratch.
Try this:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$all_posts = new WP_Query(array(
'posts_per_page' => 3,
'paged=' => $paged
));
and after the loop add this:
<div class="navigation">
<div class="next-posts"><?php next_posts_link('« Older Entries', $preNewsPosts->max_num_pages) ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Entries »', $preNewsPosts->max_num_pages) ?></div>
</div>
This fantastic article showed the way! http://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.