[英]Wordpress : exclude children posts from next_post_link, keep only parents
Dear Stackoverflowers, 亲爱的Stackoverflowers,
I'm having an issue using WP built-in
functions : 'next_post_link'
and 'previous_post_link'
. 使用
WP built-in
函数时遇到问题: 'next_post_link'
和'previous_post_link'
。 My theme uses a custom post type "project"
and every project post has children : 我的主题使用自定义帖子类型
"project"
,每个项目帖子都有子级:
My problem is that when I use "next_post_link"
, the button links to a child post (ex: subpost 1)
. 我的问题是,当我使用
"next_post_link"
,该按钮链接到一个子帖子(ex: subpost 1)
。 I want it to link only to a parent project item (ex: project 2). 我希望它仅链接到父项目项(例如:项目2)。
<?php
query_posts('post_type=projet&post_status=publish&name='.$postname);
if (have_posts()) :
while (have_posts()) :
the_post();
global $post;
previous_post_link(); // output a link to a sub-project
next_post_link(); // output a link to a sub-project
endwhile;
endif;
?>
According to the codex , you can specify the next_post_link() to lead to the "next post in the current taxonomy term". 根据法典 ,您可以指定next_post_link()引至“当前分类法术语中的下一个帖子”。 Assign a category to your custom post type, maybe "projects" and try this:
为您的自定义帖子类型分配一个类别,可能是“项目”,然后尝试以下操作:
<?php
query_posts('post_type=projet&post_status=publish&name='.$postname);
if (have_posts()) :
while (have_posts()) :
the_post();
global $post;
previous_post_link($in_same_cat = true, $taxonomy = 'project'); // output a link to a sub-project
next_post_link($in_same_cat = true, $taxonomy = 'project'); // output a link to a sub-project
endwhile;
endif;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.