[英]wordpress next_post_link() only from current child category
I've created a custom loop that only displays one post at a time, the navigation between posts is done using next_post_link()
and previous_post_link()
. 我创建了一个自定义循环,一次只显示一个帖子,使用
next_post_link()
和previous_post_link()
完成了帖子之间的导航。
The problem is that my post hierarchy includes a parent category which is common to many posts, and I want to navigate only to posts in that child category. 问题是我的帖子层次结构包含许多帖子共有的父类别,并且我只想导航到该子类别中的帖子。
The links are enabling navigations between all the posts from the parent category as well. 这些链接还允许在父类别的所有帖子之间进行导航。
I've done some research and I can't find a fix for this, any idea? 我已经做过一些研究,但找不到解决办法,有什么主意吗?
Code: 码:
<div class="setas-next">
<?php previous_post_link('%link', '»', TRUE); ?>
</div>
<div class="setas-prev">
<?php next_post_link('%link', '«', TRUE); ?>
</div>
I'm creating this navigation in both loop.php
and loop-single.php
. 我正在
loop.php
和loop-single.php
创建此导航。
Thanks, 谢谢,
Ricardo 里卡多
It's been a while since I was working in Wordpress, but I have found that for more complicated pagination needs like this you may be best served working with a WP_Query ( http://codex.wordpress.org/Class_Reference/WP_Query ) to use the exact ids of the Child category you want and then use the post IDs to find the next and previous to the one currently being used. 自从我在Wordpress中工作以来已经有一段时间了,但是我发现,对于像这样的更复杂的分页需求,最好使用WP_Query( http://codex.wordpress.org/Class_Reference/WP_Query )来使用您想要的子类别的确切ID,然后使用帖子ID查找当前使用的ID的下一个和上一个。
Mind your edge cases with this, your most recent post in particular is not going to have one more recent ... at least not right away ;) 请注意这一点,尤其是您最近的帖子不会再有新的帖子了……至少不是马上;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.