简体   繁体   English

仅来自当前子类别的wordpress next_post_link()

[英]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.phploop-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.

相关问题 WordPress:从next_post_link排除儿童帖子,仅保留父母 - Wordpress : exclude children posts from next_post_link, keep only parents Wordpress next_post_link / previous_post_link不属于同一类别 - Wordpress next_post_link/previous_post_link not staying in same category 如何从next_post_link和previous_post_link(Wordpress)中排除某些类别? - How to exclude some Categories from next_post_link and previous_post_link (Wordpress)? 将Google Analytics添加到Wordpress的next_post_link功能 - Adding Google Analytics to Wordpress' next_post_link function Wordpress:将if-else语句插入next_post_link()/ previous_post_link()参数? - Wordpress: Inserting if-else statement into next_post_link() / previous_post_link() parameters? Wordpress:previous_post_link / next_post_link按字母顺序排列? - Wordpress: previous_post_link / next_post_link by alphabetical order? 如何将PHP代码放入wordpress分页功能(previous_post_link,next_post_link等)中? - How to put PHP code in wordpress pagination function (previous_post_link,next_post_link,etc)? WordPress-next_post_link / previous_post_link提供文本而不是链接 - Wordpress - next_post_link/previous_post_link giving text instead of links 如何在简码中显示 previous_post_link () / next_post_link () - Wordpress - How to show previous_post_link () / next_post_link () in shortcode - Wordpress WordPress-next_post_link()不按post_type过滤,什么也没显示 - Wordpress - next_post_link() not filtering by post_type showing nothing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM