Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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
    -Dan

    #1030553

    Hey 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,
    Victoria

    #1030584

    Here you go

    #1031597

    Hi,

    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,
    Ismael

    #1031757

    Hi, 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 /HydroInformatics

    It should be
    Home /Solutions/ Water & Environmental Resources /Services /HydroInformatics

    Thanks
    -Dan

    #1032437

    Hi,

    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,
    Ismael

    #1032667

    ahh i see. Got it. Thanks!

    #1032705

    Hi,

    Did you need additional help, or shall we close this thread?

    Best regards,
    Jordan Shannon

    #1032712

    Please close it.

    thanks

    #1032802

    Hi,

    If you need additional help, please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Breadcrumbs not showing all grandparent/parent/child’ is closed to new replies.