专家!我正试图在每页5个帖子中分页。但我正在使用WP_Query。你能指点一下我可以获得信息来完成它吗?感谢。
<?php $preNewsPosts = new WP_Query();
$preNewsPosts->query('category_name=news&posts_per_page=30');
while($preNewsPosts->have_posts()): $preNewsPosts->the_post();
?>
<a href="<?php the_permalink(); ?>" ><?php the_post_thumbnail( 'thumbnail' ); ?></a>
<hr style="width: 95%; border: 1px solid #e6e6e6; " />
<?php
endwhile;
?>
答案 0 :(得分:0)
以下是one article详细说明如何使用自定义WP_Query完成分页。
基本上你修改你的代码,看起来像这样:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$preNewsPosts = new WP_Query();
$preNewsPosts->query('category_name=news&posts_per_page=30&paged=' . $paged);
while($preNewsPosts->have_posts()): $preNewsPosts->the_post();
?>
<a href="<?php the_permalink(); ?>" ><?php the_post_thumbnail( 'thumbnail' ); ?></a>
<hr style="width: 95%; border: 1px solid #e6e6e6; " />
<?php
endwhile;
?>
<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>