Viewing 24 posts - 1 through 24 (of 24 total)
  • Author
    Posts
  • #852371

    Thanks for the great theme and fantastic support!

    I’m running into a few issues with breadcrumbs and custom post types.

    First, I need to insert a custom page into the breadcrumb trail for several CPTs; divisions-programs, degrees-certificates.
    The following link seems like exactly what I need, but I’ve tried many variations of it and others, but cannot get it to work. It just shows two of the current page as the breadcrumb – no matter what I put in the variables. https://kriesi.at/support/topic/breadcrumbs-for-custom-post-type/

    What exists:
    Home / Divisions & Programs / Business Division
    What I want:
    Home / CUSTOM_PAGE / Divisions & Programs / Business Division

    Second, the post Business Division has a child called Accounting Program. The URL properly reflects this parent child relationship, but the breadcrumb does not.
    URL: example.com/divisions-programs/business-division/accounting-program/
    Breadcrumb: Home / Divisions & Programs / Accounting Program

    How can I get the breadcrumb to show this parent/child relationship? Like this:
    Home / CUSTOM_PAGE / Divisions & Programs / Business Division / Accounting Program

    Thanks in advance!

    #853650

    Hey psstudiosinc,

    Thank you for using Enfold.

    I logged in to the site but I can’t find the custom post types. Please provide a link to the actual custom posts. What happens after adding the filter from the previous thread?

    Best regards,
    Ismael

    #854088

    Ismael,

    Sorry for the confusion. We were having some trouble with our server right when you were in there and needed to turn off all plugins to do some testing. That why there were no CPTs.

    re: adding the filter from prev thread: It just shows two of the current page as the breadcrumb – no matter what I put in the variables. So that filter is not in the function file at the moment. Feel free to add it and test it.

    Please take another look. Thanks!

    #854232

    Hi,

    I’m trying to login again to the site but it is taking me to the “microsoft” site. That’s odd.

    Best regards,
    Ismael

    #854523

    Hi Ismael,

    Make sure to go to the following link:

    #854792

    Hi,

    The link takes me to the following page.

    // https://imgur.com/a/Wpf2c

    Best regards,
    Ismael

    #855139

    Ismael,

    Not sure why its doing that for you. I’ve disabled that plugin so you should not be redirected. Please try again.

    Thanks for sticking with me on this!

    #855649

    Hi,

    I’m sorry but it’s still not working. Why do you have to redirect to the “microsoft” site? What is the plugin?

    Best regards,
    Ismael

    #857219

    Hi Ismael,

    Wow. I’m so sorry we’re having so much trouble. The plugin redirecting you was “miniOrange SSO using SAML 2.0” but that was disabled. The site may have been cached for you. In any case, I reinstalled the site on a different server, with the miniorange and caching plugins disabled. So I’m hoping you’ll be able to login without issue. (see below)

    Again, thanks for sticking with this!

    #858350

    Hi,

    Thank you for the update. The custom posts have no “category” taxonomy. What is the name of the custom taxonomy?

    Best regards,
    Ismael

    #858584

    The custom taxonomy for the CPT Divisions and Programs is “Division Type”.

    #859090

    Hi,

    I checked the “business-division” page and it is post, not an archive or category. How is it related to the “accounting-program”?

    Best regards,
    Ismael

    #859333

    Ismael,

    Yes, the Business Division is a post in the Divisions and Programs CPT. Its category is Division.
    The “Accounting Program” is also a post in the Divisions and Programs CPT and is hierarchically inside/below the “Business Division”. Its category is Program.

    When looking at the front end breadcrumb for all Divisions & Programs posts, here is what exists:
    Home / Divisions & Programs / Business Division
    What I want:
    Home / CUSTOM_PAGE / Divisions & Programs / Business Division

    #860037

    Hi,.

    Thank you for the info.

    Please provide the FTP details in the private field so that we can test the breadcrumb filter. If you have the time, you can modify the following filter to fit the needs of the custom post type.

    add_filter('avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod', 5, 1);
    function avia_breadcrumbs_trail_mod($trail) {
        if(is_single())
        {
            global $post;
    
            $category = get_the_category($post->ID);
    
            if(!empty($category))
            {
                $home = $trail[0];
                $last = array_pop($trail);
                $trail = array(0 => $home);
    
                foreach($category as $key => $data)
                {
                    $link = '<a href="'.get_category_link($data).'">'.$data->name.'</a>';
                    $link = preg_replace('!rel=".+?"|rel=\'.+?\'|!',"", $link);
                    $link = str_replace('<a ', '<a rel="v:url" property="v:title" ', $link);
                    $link = '<span typeof="v:Breadcrumb">'.$link.'</span>';
                    $trail[] = $link;
                }
    
                $trail[] = $last;
            }
        }
        return $trail;
    }

    The filter above inserts the post categories but you can modify it for custom post type taxonomies.

    Best regards,
    Ismael

    #862206

    Hi Ismael,

    FTP credentials in private comments.

    I did attempt to modify this code for use with custom post type taxonomies without success. Sorry, I’ll need a bit more guidance. And thanks for your help!

    #862361

    Hi,

    The “Accounting Program” is also a post in the Divisions and Programs CPT and is hierarchically inside/below the “Business Division”. Its category is Program.

    We added the filter in the functions.php file. Please let us know if that’s what you’re after. ( see private field )

    Best regards,
    Ismael

    #862616

    Ismael,

    Thank you, that worked, but has a few issues. (https://imgur.com/a/upfvU)
    1. when on accounting program – the breadcrumb looks good as it now matches the url: /divisions-programs/business-division/accounting-program/ However, the Business Division breadcrumb is incorrect. It links to the Accounting Program, instead of the Business Division.
    2. when on the business division(/divisions-programs/business-division/) – the breadcrumb has itself as a parent:
    (Home/Divisions & Programs /Business Division /Business Division)

    #863215

    Hi,

    We adjusted the filter a bit. Please check it again.

    Best regards,
    Ismael

    #863594

    Hi Ismael,

    Thanks so much for your work on this.
    Number 2 from above is now resolved, that’s awesome!

    Number 1, when you’re on the child (Accounting program) of a parent(Business Division), the breadcrumb link for the parent (Business Division) is still incorrect – linking to the child (Accounting Program) instead.

    How can this be fixed?

    Best regards,
    Marc

    #863909

    Hi,

    We adjusted the permalink.

    add_filter('avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod_division', 5, 1);
    function avia_breadcrumbs_trail_mod_division($trail) {
        if(is_single())
        {
            global $post;
    
    		if( $post->post_type !== 'divisions-programs' ) return $trail;
    
            $parentID = wp_get_post_parent_id($post->ID);
    
    		if($parentID == 0) return $trail;
    
    		$parent = get_post($parentID);
    
            if(!empty($parent))
            {
                $home = $trail[0];
                $last = array_pop($trail);
    
                $link = '<a href="'.get_the_permalink($parent->ID).'">'.$parent->post_title.'</a>';
                $link = preg_replace('!rel=".+?"|rel=\'.+?\'|!',"", $link);
                $link = str_replace('<a ', '<a rel="v:url" property="v:title" ', $link);
                $link = '<span typeof="v:Breadcrumb">'.$link.'</span>';
                $trail[2] = $link;
    
    			$trail = array(0 => $home, 1 => $trail[1], 2 => $link, 'trail_end' => $last);
            }
        }
        return $trail;
    }
    

    Best regards,
    Ismael

    #867928

    Ismael,

    Looks and works great. Thank you!

    Last thing: I’m trying to manually insert a page, “Academics”, into the breadcrumb trail after the ‘Home’ link – so it matches the menu structure of the site. When I do, it works at the child level but fails at the parent level. The linking also becomes incorrect as you go up the chain.

    Is there a way to manually insert a page into the breadcrumb function you have provided?

    Here is what I tried:

    add_filter('avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod_division', 5, 1);
    function avia_breadcrumbs_trail_mod_division($trail) {
        if(is_single())
        {
            global $post;
    
            if( $post->post_type !== 'divisions-programs' ) return $trail;
    
            $parentID = wp_get_post_parent_id($post->ID);
    
            if($parentID == 0) return $trail;
    
            $parent = get_post($parentID);
    
            if(!empty($parent))
            {
                $home = $trail[0];
                $last = array_pop($trail);
    
                $link_inserted = '<a href="/academics/">Academics</a>';
                $link = '<a href="'.get_the_permalink($parent->ID).'">'.$parent->post_title.'</a>';
                $link = preg_replace('!rel=".+?"|rel=\'.+?\'|!',"", $link);
                $link = str_replace('<a ', '<a rel="v:url" property="v:title" ', $link);
                $link = '<span typeof="v:Breadcrumb">'.$link.'</span>';
                $trail[2] = $link;
    
                $trail = array(0 => $home, 1 => $link_inserted, 2 => $trail[1], 3 => $link, 'trail_end' => $last);
            }
        }
        return $trail;
    }
    #868514

    Hi,

    Glad it is working. Please try this code.

    add_filter('avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod_division', 5, 1);
    function avia_breadcrumbs_trail_mod_division($trail) {
        if(is_single())
        {
            global $post;
    
            $home = $trail[0];
            $last = array_pop($trail);
    
            $link_inserted = '<a href="/academics/">Academics</a>';
            $trail2 = array(0 => $home, 1 => $link_inserted, 2 => $trail[1], 'trail_end' => $last);
    
            if( $post->post_type !== 'divisions-programs' ) return $trail2;
    
            $parentID = wp_get_post_parent_id($post->ID);
    
            if($parentID == 0) return $trail2;
    
            $parent = get_post($parentID);
    
            if(!empty($parent))
            {
                $link = '<a href="'.get_the_permalink($parent->ID).'">'.$parent->post_title.'</a>';
                $link = preg_replace('!rel=".+?"|rel=\'.+?\'|!',"", $link);
                $link = str_replace('<a ', '<a rel="v:url" property="v:title" ', $link);
                $link = '<span typeof="v:Breadcrumb">'.$link.'</span>';
                $trail[2] = $link;
    
                $trail = array(0 => $home, 1 => $link_inserted, 2 => $trail[1], 3 => $link, 'trail_end' => $last);
            }
        }
        return $trail;
    }

    Best regards,
    Ismael

    #868993

    It works perfectly. Thanks so much for your help with this!

    #869122

    Hi,

    No problem. Please let us know if you need anything else.

    Best regards,
    Ismael

Viewing 24 posts - 1 through 24 (of 24 total)
  • The topic ‘customize breadcrumb trail for custom post types’ is closed to new replies.