告诉我如何在CPT中设置面包屑的完整路径。
我有- Post类型和分类
代码打印在面包屑-/分类法/名称中,如何打印Post类型/分类法/名称?
function the_breadcrumb() {
     global $post;
     if (!is_front_page()) {
        echo 'Главная';
        echo " ";
        if (is_category() || is_single() || is_tax()) {
             $categories = wp_get_post_terms( $post->ID, "tip" );
             if (empty($categories)) {$categories = get_the_category();}
             echo '':' class="active">');
             echo esc_html($categories[0]->name);
             echo ((is_single())?'':'').'';
             if (is_single()) {
                echo '';
                the_title();
                echo "";
              }
         } elseif (is_page()) {
            // Standard page
            if( $post->post_parent ){ 
            // If child page, get parents 
            $anc = get_post_ancestors( $post->ID );
            // Get parents in the right order
            $anc = array_reverse($anc);
            // Parent page loop
            if ( !isset( $parents ) ) $parents = null;
            foreach ( $anc as $ancestor ) {
                $parents .= '' . get_the_title($ancestor) . '';
            }
            // Display parent pages
            echo $parents;
            // Current page
            echo ''. get_the_title() . '';
       }
       else {
            // Just display current page if not parents
            echo ''. get_the_title() . '';
        }
     }
    else {
       echo 'Home';
    }
   }
 }CPT设置

自定义Post型Permalinks

发布于 2019-03-18 08:27:14
代码打印在面包屑-/分类法/名称中,如何打印Post类型/分类法/名称?
如果我正确理解了您的问题,您希望将自定义post类型名称添加到现有的面包屑中.对代码的这种修改可能会有所帮助。
function the_breadcrumb() {
     global $post;
     if (!is_front_page()) {
        echo 'Главная';
        echo " ";
        if (is_category() || is_single() || is_tax()) {
             $categories = wp_get_post_terms( $post->ID, "tip" );
             if (empty($categories)) {$categories = get_the_category();}
             //  Add your Post type here
            $postType = get_post_type_object(get_post_type());
            if ($postType) {
                 $post_type_title =  esc_html($postType->labels->singular_name);
                 $post_type_link = get_post_type_archive_link( get_post_type( ) );    
                 echo '';
                 echo $post_type_title.'';
             }
             // Rest of code ....https://wordpress.stackexchange.com/questions/331872
复制相似问题