简体   繁体   中英

Pagination with Wordpress

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('&laquo; Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></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.

http://wordpress.org/extend/plugins/wp-pagenavi/

http://wordpress.org/extend/plugins/wp-paginate/

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('&laquo; Older Entries', $preNewsPosts->max_num_pages) ?></div>
    <div class="prev-posts"><?php previous_posts_link('Newer Entries &raquo;', $preNewsPosts->max_num_pages) ?></div>
</div>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM