在学习如何从头开始构建WordPress主题时,我在尝试编写home.php. 我遇到的问题是分页。在文章的最后一页之后,它不再停止/禁用按钮,而是启用按钮并单击后加载/page/# 使用index.php 文件,此时仅为<?php get_header(); ?> 和<?php get_footer(); ?>. 我测试过的功能<?php next_posts_link(); ?> 和<?php echo get_next_posts_link(); ?>. 我对此进行了一段时间的研究,偶然发现它可能与permalinks有关,它们设置为post name.
代码输入home.php:
<?php
if ( have_posts() ): while ( have_posts() ): the_post(); ?>
<div class="thepost">
<div class="primecircle">
<div class="circledate">
<div class="blogmonth"><?php the_time(\'M\'); ?></div>
<div class="blogdate"><?php the_time(\'j\'); ?></div>
<div class="blogyear"><?php the_time(\'Y\'); ?></div>
</div>
</div>
<div class="blogcontent">
<h1 class="blogtitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<p><?php the_excerpt(); ?></p>
<div class="learnmore"><a href="<?php the_permalink(); ?>">learn more</a></div>
</div>
</div>
<?php endwhile; ?>
<div class="pagelinks">
<ul class="tags" class="list-inline">
<li><?php echo previous_posts_link(\'Back\'); ?></li>
<li><?php echo next_posts_link(\'Next\', 5); ?></li>
</ul>
</div>
<?php else: ?>
<h1 class="blogtitle">No Current blog posts at this time.</h1>
<?php endif; ?>
关于如何正确禁用
next_posts_link() 当它到达文章的最后一页时是否起作用?
编辑:功能上的调整错误previous_posts_link(); 当我经过的时候label 和max_page 当它只需要label. 移除后max_page 从这两个功能中,它停止循环index.php.