【发布时间】:2016-03-16 11:52:42
【问题描述】:
这是我的设置。
single.php
<?php
if ( in_category( 'my-category' ) ) {
include( TEMPLATEPATH.'/single-my-category.php' );
}
else {
include( TEMPLATEPATH.'/single-generic.php' );
}
?>
single-my-category.php
<?php
if ( have_posts() ) : while (have_posts()) : the_post(); ?>
<?php echo the_title(); ?>
<div class="pagination">
<div class="container">
<div class="row">
<div class="next col-xs-6 col-sm-6 col-md-6 col-lg-6">
<?php next_post_link( '%link', '<img src="' . get_template_directory_uri() . '/img/cs-left.png" /> PREVIOUS', true ); ?>
</div>
<div class="previous col-xs-6 col-sm-6 col-md-6 col-lg-6">
<?php previous_post_link( '%link', 'NEXT <img src="' . get_template_directory_uri() . '/img/cs-right.png" />', true ); ?>
</div>
</div>
</div>
</div>
<?php endwhile; endif; ?>
这就是我所关注的 - http://codex.wordpress.org/Function_Reference/next_post_link
我不太确定我在这里做错了什么,因为由于某种原因,previous_post_link 将我带到不同类别的帖子,即使函数的 in_same_term 参数设置为 true。
有什么想法吗?
谢谢。
【问题讨论】:
-
发生这种情况是因为您的帖子中有多个类别,而 wp 只是转到帖子中的第一个类别(猜测)。检查this link here。 this answer 也可能会有所帮助。
-
帖子只分配到1个类别
-
你可以试试loop下面的分页链接
-
你确定这篇文章只分配到 1 个类别吗?是否可能仍将其分配给未分类?它也是一个类别,它在数据库中的 ID 最低。
-
另外,我希望你没有使用缓存插件。