-
AuthorPosts
-
November 5, 2018 at 9:51 pm #1030062
Hi,
Im having an issue with my breadcrumbs. I have already tried one fix and it did help but im still not getting all the pages to show up in the breadcrumbs. It should show all parent pages and mimic the URL structure.
Take a look at this page.
Custom post type is “Solutions” and we have 3 pages after that “Water Environmental Resources” > “Services” > “Hydroinformatics”.
The breadcrumbs are missing “Water Environmental Resources”.
This is the current code I have added to help the breadcrumbs that i found in another support thread.
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 !== 'solutions' ) 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; }
I need all the pages to show up in the breadcrumbs.
Thanks
-DanNovember 6, 2018 at 8:15 pm #1030553Hey acscreativenew,
Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look?
Best regards,
VictoriaNovember 6, 2018 at 8:55 pm #1030584Here you go
November 9, 2018 at 10:29 am #1031597Hi,
Thanks for the update.
You can try this filter:
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 !== 'solutions' ) 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 = array(0 => $home, 1 => $trail[1], 2 => $link, 'trail_end' => $last); } $grandparentID = wp_get_post_parent_id( $parent->ID) ; if( $grandparentID == 0 ) return $trail; $grandparent = get_post( $grandparentID ); if( ! empty( $grandparent ) ) { $home = $trail[0]; $last = array_pop($trail); $link = '<a href="'.get_the_permalink($grandparent->ID).'">'.$grandparent->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 = array( 0 => $home, 1 => $link, 2 => $trail[1], 3 => $trail[2], 'trail_end' => $last ); } } return $trail; }
Best regards,
IsmaelNovember 9, 2018 at 6:39 pm #1031757Hi, This is great and a set in the right direction. I this there are still some issues. I was able to fix one. but think i will need your help with the second. Here is my modified code.
All I did was remove the part that made this only for the Solutions post type. I want it this way for every page.
add_filter( 'avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod_division', 5, 1 ); function avia_breadcrumbs_trail_mod_division( $trail ) { if( is_single() ) { global $post; $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 = array(0 => $home, 1 => $trail[1], 2 => $link, 'trail_end' => $last); } $grandparentID = wp_get_post_parent_id( $parent->ID) ; if( $grandparentID == 0 ) return $trail; $grandparent = get_post( $grandparentID ); if( ! empty( $grandparent ) ) { $home = $trail[0]; $last = array_pop($trail); $link = '<a href="'.get_the_permalink($grandparent->ID).'">'.$grandparent->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 = array( 0 => $home, 1 => $link, 2 => $trail[1], 3 => $trail[2], 'trail_end' => $last ); } } return $trail; }
Where im still having issues is check out this page.
You can see the slug is
/solutions/water-environmental-resources/services/hydroinformatics/But the bread crumbs are
Home /Water & Environmental Resources /Solutions /Services /HydroInformaticsIt should be
Home /Solutions/ Water & Environmental Resources /Services /HydroInformaticsThanks
-DanNovember 12, 2018 at 6:02 am #1032437Hi,
Try to re-arrange the trail on this line.
$trail = array( 0 => $home, 1 => $link, 2 => $trail[1], 3 => $trail[2], 'trail_end' => $last );
$link goes to array key 2 and $trail[1] to key 1 etc.
Best regards,
IsmaelNovember 12, 2018 at 5:24 pm #1032667ahh i see. Got it. Thanks!
November 12, 2018 at 7:29 pm #1032705Hi,
Did you need additional help, or shall we close this thread?
Best regards,
Jordan ShannonNovember 12, 2018 at 7:42 pm #1032712Please close it.
thanks
November 13, 2018 at 12:08 am #1032802Hi,
If you need additional help, please let us know here in the forums.
Best regards,
Jordan Shannon -
AuthorPosts
- The topic ‘Breadcrumbs not showing all grandparent/parent/child’ is closed to new replies.