Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #810285

    NeversDesign
    Participant

    I’m having issue with the breadcrumb for my custom post types.

    I’ve incorporated the custom code from this post https://community.theme.co/forums/topic/custom-post-types-6/:

    } elseif ( is_singular( get_post_type( get_the_ID() ) ) && ! is_page() ) {
    
              $post_type = get_post_type( get_the_ID() );
              $obj = get_post_type_object( $post_type );
              $type_name = $obj->labels->name;
    
              if ( get_option( 'page_for_posts' ) == is_front_page() ) {
                echo $current_before . $page_title . $current_after;
              } else {
                if ( $is_ltr ) {
                  echo '<a href="' . get_post_type_archive_link( $post_type ) . '">' . $type_name . '</a>' . $delimiter . $current_before . $page_title . $current_after;
                } else {
                  echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . get_post_type_archive_link( $post_type ) . '">' . $type_name . '</a>';
                }
              }
    
            } elseif ( x_is_portfolio() ) {

    However, the custom posts appear to be selecting echo $current_before . $page_title . $current_after; instead of the full breadcrumb, with the archive link, it’s only displaying the page title.

    Since this seems to work for most others, I’ve narrowed the issue down to a couple of possible things:

    1. An incorrect label/setting in my CPT’s – is there a list of ideal settings for the breadcrumb to work properly?
    2. A Communication/Access issue between the CPT plugin (Types) and the theme – I haven’t seen very many posts from Toolset users in the forums
    3. A PHP issue (I’ll explain below)

    Any help you can offer would be most appreciated – details to follow

    #810295

    NeversDesign
    Participant
    This reply has been marked as private.
    #810420

    Thai
    Moderator

    Hi There,

    #1] Breabcrumb: Please update your PHP code with this:

    } elseif ( is_singular( 'staff-member' ) && ! is_page() ) {
    
    	if ( get_option( 'page_for_posts' ) == is_front_page() ) {
    		echo $current_before . $page_title . $current_after;
    	} else {
    		if ( $is_ltr ) {
    			echo '<a href="' . get_post_type_archive_link( 'staff-member' ) . '">' . 'Staff' . '</a>' . $delimiter . $current_before . $page_title . $current_after;
    		} else {
    			echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . get_post_type_archive_link( 'staff-member' ) . '">' . 'Staff' . '</a>';
    		}
    	}
    
    } elseif ( x_is_portfolio() ) {

    #2] PHP issue: could you please contact to your hosting provider update your PHP to version 5.5?

    Let us know how it goes!

    #810767

    NeversDesign
    Participant

    No change with the cpt-specific code – breadcrumb still only shows the $page_title

    As I mentioned, I can’t change the PHP version yet, as the legacy site needs the set version to operate – once I get authorization to take the old site down, I can change the PHP version and see if that fixes the breadcrumb issue, unless we can find a solution before that.

    On perhaps a simpler note, is there a way on the archive pages for the custom post types to have the breadcrumb read anything besides ‘Archives’? Or is that meant to be covered by this statement:

    if ( get_option( 'page_for_posts' ) == is_front_page() ) {
    		echo $current_before . $page_title . $current_after;
    	}

    If it is, it means the entire condition is being skipped, and the archive pages are being caught by the last condition in the breadcrumb code:

    } elseif ( is_archive() ) {
    
              if ( x_is_shop() ) {
                echo $current_before . $shop_title . $current_after;
              } else {
                echo $current_before . __( 'Archives ', '__x__' ) . $current_after;
              }
    
            }

    Ultimately, if the problem is caused by the PHP version, I’ll know soon enough; but, if there’s a chance it’s not, is there anything else I can try?

    #811236

    Rue Nel
    Moderator

    Hello Again,

    You could try a more simplified code for your single custom post type breadcrumb. Please make use of this code:

    } elseif ( is_singular( 'staff-member' ) ) {
    	
    	echo $current_before . '<a href="' . get_post_type_archive_link( 'staff-member' ) . '">' . 'Staff' . '</a>' . $delimiter . $page_title . $current_after;
    
    } elseif ( x_is_portfolio() ) {

    We would loved to know if this has work for you. Thank you.

    #812087

    NeversDesign
    Participant

    Brilliant! That worked perfectly – Just means I’ll have to manually add the code for each CPT, but I’ll take it!

    I’ll still try the original code when I’m able to change the PHP version, so that I can have this process automated (and transferable), but this will work for now.

    Thanks!

    #812485

    Jade
    Moderator

    You’re welcome. 🙂