简体   繁体   English

WordPress:从next_post_link排除儿童帖子,仅保留父母

[英]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" ,每个项目帖子都有子级:

  • Project 1 项目1
    • subpost 1 分档1
    • subpost 2 分档2
    • subpost 3 分档3
  • Project 2 项目二
    • subpost 1 分档1
    • subpost 2 分档2
    • subpost 3 分档3
  • ... etc ...等等

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.

相关问题 仅来自当前子类别的wordpress next_post_link() - wordpress next_post_link() only from current child 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 next_post_link / previous_post_link不属于同一类别 - Wordpress next_post_link/previous_post_link not staying in same category 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