YOAST Breadcrumb 未显示自定义帖子父链接

问题描述

我不明白为什么我的 Yoast 面包屑没有显示我想要实现的面包屑结构:

主页 > 我们的工作 > 生物多样性保护 > ... 而不是当前版本主页 > 生物多样性保护

这是可以帮助我的人的自定义帖子类型和类别代码

// Custom Post Type + Custom Taxonomy

add_action('init','projects_cpt');
function projects_cpt() {
    $labels = array(
        'name' => 'Our Work','singular_name' => 'Project','add_new' => 'Add New','add_new_item' => 'Add New Project','edit_item' => 'Edit Project','new_item' => 'New Project','all_items' => 'All Projects','view_item' => 'View Project','search_items' => 'Search Projects','not_found' => 'No projects found','not_found_in_trash' => 'No projects found in Trash','parent_item_colon' => '','menu_name' => 'Our Work'
    );
    $args = array(
        'labels' => $labels,'public' => true,'publicly_queryable' => true,'show_ui' => true,'show_in_menu' => true,'query_var' => true,'taxonomies' => array('projectstype'),'rewrite' => array('slug' => 'our-work/%projectscategory%','with_front' => false),//Adding custom rewrite tag
        'capability_type' => 'post','has_archive' => 'our-work','hierarchical' => false,'menu_position' => null,'supports' => array('title','editor','author','thumbnail','excerpt'),);
    register_post_type('our-work',$args);

    $labels = array(
        'name' => 'Projects Categories','singular_name' => 'Projects','search_items' => 'Search Projects Categories','all_items' => 'All Projects Categories','parent_item' => 'Parent Project Category','parent_item_colon' => 'Parent Project Category:','edit_item' => 'Edit Project Category','update_item' => 'Update Project Category','add_new_item' => 'Add New Project Category','new_item_name' => 'New Project Category',);

    $args = array(
        'hierarchical' => true,'rewrite' => array('slug' => 'our-work'),'show_in_nav_menus' => true,'show_admin_column' => true,'labels' => $labels
    );

    register_taxonomy('projectscategory','our-work',$args);

    unset($labels);
    unset($args);
}

add_filter('post_type_link','projectcategory_permalink_structure',10,4);
function projectcategory_permalink_structure($post_link,$post,$leavename,$sample) {
    if (false !== strpos($post_link,'%projectscategory%')) {
        $projectscategory_type_term = get_the_terms($post->ID,'projectscategory');
        if (!empty($projectscategory_type_term))
            $post_link = str_replace('%projectscategory%',array_pop($projectscategory_type_term)->
            slug,$post_link);
        else
            $post_link = str_replace('%projectscategory%','uncategorized',$post_link);
    }
    return $post_link;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)