$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>custom post types - How to configure the output of breadcrumbled CPT UI|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

custom post types - How to configure the output of breadcrumbled CPT UI

matteradmin7PV0评论

Tell me how to set the full path in bread crumbs in CPT UI.

I have - Post type and taxonomy

The code prints in breadcrumbs - / Taxonomy / Name, how to do what would print Post type / Taxonomy / Name?

function the_breadcrumb() {
     global $post;
     if (!is_front_page()) {
        echo '<li><a href="';
        echo get_option('home');
        echo '">Главная';
        echo "</a></li> ";
        if (is_category() || is_single() || is_tax()) {

             $categories = wp_get_post_terms( $post->ID, "tip" );
             if (empty($categories)) {$categories = get_the_category();}
             echo '<li'.((is_single())?'><a href="'.
             esc_url(get_term_link($categories[0]->slug,$categories[0]->taxonomy)) . '">':' class="active">');
             echo esc_html($categories[0]->name);
             echo ((is_single())?'</a>':'').'</li>';
             if (is_single()) {
                echo '<li class="active">';
                the_title();
                echo "</li>";

              }
         } 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 .= '<li><a href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a></li>';

            }

            // Display parent pages
            echo $parents;

            // Current page
            echo '<li class="active">'. get_the_title() . '</li>';

       }
       else {

            // Just display current page if not parents
            echo '<li class = "active">'. get_the_title() . '</li>';

        }
     }
    else {
       echo 'Home';
    }
   }
 }

CPT UI Setting

Custom Post Type Permalinks

Tell me how to set the full path in bread crumbs in CPT UI.

I have - Post type and taxonomy

The code prints in breadcrumbs - / Taxonomy / Name, how to do what would print Post type / Taxonomy / Name?

function the_breadcrumb() {
     global $post;
     if (!is_front_page()) {
        echo '<li><a href="';
        echo get_option('home');
        echo '">Главная';
        echo "</a></li> ";
        if (is_category() || is_single() || is_tax()) {

             $categories = wp_get_post_terms( $post->ID, "tip" );
             if (empty($categories)) {$categories = get_the_category();}
             echo '<li'.((is_single())?'><a href="'.
             esc_url(get_term_link($categories[0]->slug,$categories[0]->taxonomy)) . '">':' class="active">');
             echo esc_html($categories[0]->name);
             echo ((is_single())?'</a>':'').'</li>';
             if (is_single()) {
                echo '<li class="active">';
                the_title();
                echo "</li>";

              }
         } 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 .= '<li><a href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a></li>';

            }

            // Display parent pages
            echo $parents;

            // Current page
            echo '<li class="active">'. get_the_title() . '</li>';

       }
       else {

            // Just display current page if not parents
            echo '<li class = "active">'. get_the_title() . '</li>';

        }
     }
    else {
       echo 'Home';
    }
   }
 }

CPT UI Setting

Custom Post Type Permalinks

Share Improve this question edited Mar 19, 2019 at 10:33 starspro asked Mar 17, 2019 at 15:17 starsprostarspro 33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The code prints in breadcrumbs - / Taxonomy / Name, how to do what would print Post type / Taxonomy / Name?

If I understood your question correctly, you want to prepend custom post type name to the existing breadcrumb... This modification to your code may help.

function the_breadcrumb() {
     global $post;
     if (!is_front_page()) {
        echo '<li><a href="';
        echo get_option('home');
        echo '">Главная';
        echo "</a></li> ";
        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 '<li><a href="'. $post_type_link . '">';
                 echo $post_type_title.'</a></li>';
             }




             // Rest of code ....
Post a comment

comment list (0)

  1. No comments so far