Tagged: breadcrumb, Custom Post Type
-
AuthorPosts
-
September 15, 2017 at 2:08 am #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 DivisionSecond, 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 ProgramHow can I get the breadcrumb to show this parent/child relationship? Like this:
Home / CUSTOM_PAGE / Divisions & Programs / Business Division / Accounting ProgramThanks in advance!
September 19, 2017 at 3:30 am #853650Hey 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,
IsmaelSeptember 19, 2017 at 11:55 pm #854088Ismael,
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!
September 20, 2017 at 7:51 am #854232Hi,
I’m trying to login again to the site but it is taking me to the “microsoft” site. That’s odd.
Best regards,
IsmaelSeptember 20, 2017 at 6:18 pm #854523Hi Ismael,
Make sure to go to the following link:
September 21, 2017 at 12:40 pm #854792September 22, 2017 at 2:38 am #855139Ismael,
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!
September 23, 2017 at 3:07 am #855649Hi,
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,
IsmaelSeptember 27, 2017 at 2:04 am #857219Hi 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!
September 29, 2017 at 8:55 am #858350Hi,
Thank you for the update. The custom posts have no “category” taxonomy. What is the name of the custom taxonomy?
Best regards,
IsmaelSeptember 29, 2017 at 7:37 pm #858584The custom taxonomy for the CPT Divisions and Programs is “Division Type”.
October 2, 2017 at 6:35 am #859090Hi,
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,
IsmaelOctober 2, 2017 at 7:08 pm #859333Ismael,
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 DivisionOctober 4, 2017 at 9:00 am #860037Hi,.
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,
IsmaelOctober 10, 2017 at 1:46 am #862206Hi 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!
October 10, 2017 at 8:38 am #862361Hi,
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,
IsmaelOctober 10, 2017 at 6:33 pm #862616Ismael,
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)October 12, 2017 at 7:03 am #863215October 12, 2017 at 7:45 pm #863594Hi 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,
MarcOctober 13, 2017 at 12:54 pm #863909Hi,
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,
IsmaelOctober 24, 2017 at 1:49 am #867928Ismael,
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; }
October 25, 2017 at 4:28 am #868514Hi,
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,
IsmaelOctober 25, 2017 at 11:03 pm #868993It works perfectly. Thanks so much for your help with this!
October 26, 2017 at 8:13 am #869122 -
AuthorPosts
- The topic ‘customize breadcrumb trail for custom post types’ is closed to new replies.