【发布时间】:2019-10-29 13:02:26
【问题描述】:
我有一个博客页面,其中显示 10 篇文章,然后是带有“下一个”和“上一个”的导航。但是我们的客户需要一个编号的分页,而不仅仅是一个简单的页面导航。
帖子输出来自帖子查询,而不是来自标准的 wordpress 选项。
<section class="blog">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 10,
'paged' => $paged,
'post_type' => 'post'
);
$cpt_query = new WP_Query($args);
?>
<?php if ($cpt_query->have_posts()) : while ($cpt_query->have_posts()) : $cpt_query->the_post(); ?>
<div class="beitrag">
<div class="beitrag-inhalt">
<p><?php the_excerpt(); ?></p>
</div>
<div class="weiterlesen">
<a href="<?php the_permalink(); ?>">Mehr Lesen</a>
</div>
</div>
<?php endwhile; endif; ?>
<nav>
<?php previous_posts_link( '<i class="fas fa-angle-left"></i> Vorherige Seite', $cpt_query->max_num_pages) ?>
<?php next_posts_link( 'Nächste Seite <i class="fas fa-angle-right"></i>', $cpt_query->max_num_pages) ?>
</nav>
</section>
如何在导航中添加页码?
【问题讨论】: