0

伙计们!我正在尝试在每页 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;
    ?>
4

1 回答 1

0

这是一篇详细解释如何使用自定义 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('&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>
于 2013-04-14T11:28:23.567 回答