Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1116769
    NCodeJ
    Participant

    Hi,
    I had a
    parent category -> Story Book
    child category -> Tom and Jerry

    In my breadcrumb, it just show up Home -> Tom and Jerry
    But the parent category “Story Book” is not shown.

    I try to add in below code to my child theme function.php:

    function x_breadcrumbs() {
    	
    	global $post;
    	
        echo '<ul id="breadcrumbs">';
        if (!is_home()) {
            echo '<li><a href="';
            echo get_option('home');
            echo '">';
            echo '<i class="x-icon-home" data-x-icon=""></i>';
            echo '</a></li><li class="separator"><i class="x-icon-angle-right" data-x-icon=""></i></li>';
    		
            if (is_category() || is_single()) {
                echo '<li>';
                the_category(' </li><li class="separator"><i class="x-icon-angle-right" data-x-icon=""></i></li><li> ');
                if (is_single()) {
                    echo '</li><li class="separator"><i class="x-icon-angle-right" data-x-icon=""></i></li><li>';
                    the_title();
                    echo '</li>';
                }
    			
            } elseif (is_page()) {
                if($post->post_parent){
    				$anc = get_post_ancestors( $post->ID );
    				$title = get_the_title();
    				foreach ( $anc as $ancestor ) {
    					$output = '<li><a href="'.get_permalink($ancestor).'" title="'.get_the_title($ancestor).'">'.get_the_title($ancestor).'</a></li> <li class="separator">/</li>';
    				}
    				echo $output;
    				echo '<strong title="'.$title.'"> '.$title.'</strong>';
    			} else {
    				echo '<li><strong> '.get_the_title().'</strong></li>';
    			}
            }
        }
        elseif (is_tag()) {single_tag_title();}
        elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
        elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
        elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
        elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
        elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
        elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
        echo '</ul>';
    }
    ?>

    Is there any code i need to modified in order to show up the parent category?
    Thanks

    #1116865
    Rupok
    Member

    Hi there,

    Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

    #1118285
    NCodeJ
    Participant
    This reply has been marked as private.
    #1118534
    Rad
    Moderator

    Hi there,

    Replace this code,

    echo '<li>';
                the_category(' </li><li class="separator"><i class="x-icon-angle-right" data-x-icon=""></i></li><li> ');
                if (is_single()) {
                    echo '</li><li class="separator"><i class="x-icon-angle-right" data-x-icon=""></i></li><li>';
                    the_title();
                    echo '</li>';
                }
    		

    with this,

    $category = get_the_category(); 
    
    $category_parent_id = $category[0]->category_parent;
    if ( $category_parent_id != 0 ) {
        $category_parent = get_term( $category_parent_id, 'category' );
        echo '<li>'.$category_parent->name.'<li class="separator"><i class="x-icon-angle-right" data-x-icon=""></i></li><li>'.$category[0]->name.'</li>';
    } else {
        echo '<li>'.$category[0]->name.'</li>';
    }          
    
                if (is_single()) {
                    echo '<li class="separator"><i class="x-icon-angle-right" data-x-icon=""></i></li><li>';
                    the_title();
                    echo '</li>';
                }
    

    Hope this helps.

    #1121662
    NCodeJ
    Participant

    Hi, for your informed, the coding above did showed the parent category, but the a href permalink is missing for both the parent category and the category item.
    Any code that is miss up?

    #1121670
    Rue Nel
    Moderator

    Hello There,

    Please check out this topic:
    https://community.theme.co/forums/topic/show-category-in-breadcrumbs/#post-878067

    Please let us know how it goes.

    #1121770
    NCodeJ
    Participant
    This reply has been marked as private.
    #1121802
    Rue Nel
    Moderator

    Hello There,

    With your code, there are a lot of things missing. Please try this code instead:

    // Breadcrumbs Display Category Name
    // =============================================================================
    function get_breadcrumb_category( $cat ) {
    $post = get_post( $post->ID );
    $post_type = $post->post_type;
    $taxonomy = $cat;
    $f_categories = wp_get_post_terms( $post->ID, $taxonomy );
    $f_category = $f_categories[0];
    if ( $f_category->parent != 0 ) {
    $f_category_id    = $f_category->parent;
    $parent_array     = get_term_by('id', $f_category_id, $taxonomy, 'ARRAY_A');
    $f_category_name  = $parent_array["name"];
    $term_link        = get_term_link( $f_category_id, $taxonomy );
    } else {
    $f_category_id    = $f_category->term_id;
    $f_category_name  = $f_category->name;
    $term_link        = get_term_link( $f_category_id, $taxonomy );
    }
    if ( $f_categories && ! is_wp_error($f_categories) ) {
    return '<a href="' . $term_link . '">' . $f_category_name . '</a>';
    } else {
    return '';
    }
    }
    function x_breadcrumbs() {
    if ( x_get_option( 'x_breadcrumb_display', '1' ) ) {
    GLOBAL $post;
    $is_ltr         = ! is_rtl();
    $stack          = x_get_stack();
    $delimiter      = x_get_breadcrumb_delimiter();
    $home_text      = x_get_breadcrumb_home_text();
    $home_link      = home_url();
    $current_before = x_get_breadcrumb_current_before();
    $current_after  = x_get_breadcrumb_current_after();
    $page_title     = get_the_title();
    $blog_title     = get_the_title( get_option( 'page_for_posts', true ) );
    $post_parent    = $post->post_parent;
    if ( X_WOOCOMMERCE_IS_ACTIVE ) {
    $shop_url   = x_get_shop_link();
    $shop_title = x_get_option( 'x_' . $stack . '_shop_title', __( 'The Shop', '__x__' ) );
    $shop_link  = '<a href="'. $shop_url .'">' . $shop_title . '</a>';
    }
    echo '<div class="x-breadcrumbs"><a href="' . $home_link . '">' . $home_text . '</a>' . $delimiter;
    if ( is_home() ) {
    echo $current_before . $blog_title . $current_after;
    } elseif ( is_category() ) {
    $the_cat = get_category( get_query_var( 'cat' ), false );
    if ( $the_cat->parent != 0 ) echo '<a href="'.get_permalink(102).'">'.get_the_title(102) .'</a>';
    echo $current_before . single_cat_title( '', false ) . $current_after;
    } elseif ( x_is_product_category() ) {
    if ( $is_ltr ) {
    echo $shop_link . $delimiter . $current_before . single_cat_title( '', false ) . $current_after;
    } else {
    echo $current_before . single_cat_title( '', false ) . $current_after . $delimiter . $shop_link;
    }
    } elseif ( x_is_product_tag() ) {
    if ( $is_ltr ) {
    echo $shop_link . $delimiter . $current_before . single_tag_title( '', false ) . $current_after;
    } else {
    echo $current_before . single_tag_title( '', false ) . $current_after . $delimiter . $shop_link;
    }
    } elseif ( is_search() ) {
    echo $current_before . __( 'Search Results for ', '__x__' ) . '"' . get_search_query() . '"' . $current_after;
    } elseif ( is_singular( 'post' ) ) {
    if ( get_option( 'page_for_posts' ) == is_front_page() ) {
    echo $current_before . $page_title . $current_after;
    } else {
    if ( $is_ltr ) {
    $f_category = get_the_category();
    if ( $f_category[0]->category_parent != 0 ) {
    $f_category_id = $f_category[0]->parent;
    $f_category_name = get_cat_name( $f_category_id );
    $f_subcategory_id = $f_category[0]->cat_ID;
    $f_subcategory_name  = get_cat_name( $f_subcategory_id );
    echo '<a href="' . get_category_link( $f_category_id ) . '">' . $f_category_name . '</a>' . $delimiter 
    .'<a href="' . get_category_link( $f_subcategory_id ) . '">' . $f_subcategory_name . '</a>' . $delimiter . $current_before . $page_title . $current_after;
    } else {
    $f_category_id = $f_category[0]->term_id;
    $f_category_name = $f_category[0]->name;
    echo '<a href="' . get_category_link( $f_category_id ) . '">' . $f_category_name . '</a>' . $delimiter . $current_before . $page_title . $current_after;
    }
    } else {
    echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">' . $blog_title . '</a>';
    }
    }
    } elseif ( x_is_portfolio() ) {
    echo $current_before . get_the_title() . $current_after;
    } elseif ( x_is_portfolio_item() ) {
    $link  = x_get_parent_portfolio_link();
    $title = x_get_parent_portfolio_title();
    if ( $v = get_breadcrumb_category('portfolio-category') ) {
    $portfolio_category = $delimiter . $v;
    } else {
    $portfolio_category = '';
    }
    if ( $is_ltr ) {
    echo '<a href="' . $link . '">' . $title . '</a>' . $portfolio_category . $delimiter . $current_before . $page_title . $current_after;
    } else {
    echo $current_before . $page_title . $current_after . $portfolio_category . $delimiter . '<a href="' . $link . '">' . $title . '</a>';
    }
    } elseif ( x_is_product() ) {
    if ( $v = get_breadcrumb_category('product_cat') ) {
    $product_category = $delimiter . $v;
    } else {
    $product_category = '';
    }
    if ( $is_ltr ) {
    echo $shop_link . $product_category . $delimiter . $current_before . $page_title . $current_after;
    } else {
    echo $current_before . $page_title . $current_after . $product_category . $delimiter . $shop_link;
    }
    } elseif ( x_is_buddypress() ) {
    if ( bp_is_group() ) {
    echo '<a href="' . bp_get_groups_directory_permalink() . '">' . x_get_option( 'x_buddypress_groups_title', __( 'Groups', '__x__' ) ) . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
    } elseif ( bp_is_user() ) {
    echo '<a href="' . bp_get_members_directory_permalink() . '">' . x_get_option( 'x_buddypress_members_title', __( 'Members', '__x__' ) ) . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
    } else {
    echo $current_before . x_buddypress_get_the_title() . $current_after;
    }
    } elseif ( x_is_bbpress() ) {
    //remove_filter( 'bbp_no_breadcrumb', '__return_true' );
    if ( bbp_is_forum_archive() ) {
    echo $current_before . bbp_get_forum_archive_title() . $current_after;
    } else {
    echo bbp_get_breadcrumb();
    }
    //add_filter( 'bbp_no_breadcrumb', '__return_true' );
    } elseif ( is_page() && ! $post_parent ) {
    echo $current_before . $page_title . $current_after;
    } elseif ( is_page() && $post_parent ) {
    $parent_id   = $post_parent;
    $breadcrumbs = array();
    if ( is_rtl() ) {
    echo $current_before . $page_title . $current_after . $delimiter;
    }
    while ( $parent_id ) {
    $page          = get_page( $parent_id );
    $breadcrumbs[] = '<a href="' . get_permalink( $page->ID ) . '">' . get_the_title( $page->ID ) . '</a>';
    $parent_id     = $page->post_parent;
    }
    if ( $is_ltr ) {
    $breadcrumbs = array_reverse( $breadcrumbs );
    }
    for ( $i = 0; $i < count( $breadcrumbs ); $i++ ) {
    echo $breadcrumbs[$i];
    if ( $i != count( $breadcrumbs ) -1 ) echo $delimiter;
    }
    if ( $is_ltr ) {
    echo $delimiter . $current_before . $page_title . $current_after;
    }
    } elseif ( is_tag() ) {
    echo $current_before . single_tag_title( '', false ) . $current_after;
    } elseif ( is_author() ) {
    GLOBAL $author;
    $userdata = get_userdata( $author );
    echo $current_before . __( 'Posts by ', '__x__' ) . '"' . $userdata->display_name . $current_after . '"';
    } elseif ( is_404() ) {
    echo $current_before . __( '404 (Page Not Found)', '__x__' ) . $current_after;
    } elseif ( is_archive() ) {
    if ( x_is_shop() ) {
    echo $current_before . $shop_title . $current_after;
    } else {
    echo $current_before . __( 'Archives ', '__x__' ) . $current_after;
    }
    }
    echo '</div>';
    }
    }
    // =============================================================================

    We would loved to know if this has work for you. As this is all custom development, regretfully we won’t be able to assist further. Custom development is outside the scope of our support. We’re happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation.

    If you are looking for a partner to help with your customization needs, you may wish to check out XThemeUsers.com. This user run site is not managed by Themeco, however there are several X professionals listed there. Alternatively you can search on one of the many freelance websites or the X Theme User Group on Facebook.

    Hope this helps.

    #1121837
    NCodeJ
    Participant

    Hi,
    Thanks for your reply.
    I had try out your code, but it doesn’t work.

    The code that you gave, caused my breadcrumbs category become
    Home > Post Name –> whereby my Category is missing

    But with my previous code that i show you, it did gave me the parent category, category and post name
    Home > Parent Category -> Category -> Post Name
    BUT the issue is Parent Category and Category did not have the permalink!

    So i just need to know any code that have been missing up

    Thanks

    #1122665
    Jade
    Moderator

    Hi there,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

  • <script> jQuery(function($){ $("#no-reply-1116769 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>