Major issue with breadcrumbs

Home Forums Calendar Products Events Calendar PRO Major issue with breadcrumbs

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1067668
    Shaun
    Participant

    Hi,

    I’ve been trying to implement some sort of breadcrumbs into the events/calendar on my site for several days now.

    I’ve tried various WP plugins that have been recommended in these forums (Yoast, NavXT, Hansel & Gretel etc..) but with varying degrees of success each time but never totally as I intended.

    In an ideal world, I’d like the breadcrumbs to work like this:

    Calendar >
    Calendar > Course Category
    Calendar > Course Category > Course Title

    With all but the current level a link to the previous page. Or at least as close as I can get to that.

    Then I stumbled upon this post ‘Showing Events & Venues In Breadcrumbs’ – https://theeventscalendar.com/knowledgebase/showing-events-and-venues-in-breadcrumbs/ – and thought my prayres had been answered. It sounds like it does exactly what I want.

    But unfortunately despite copying the code to the letter it also doesn’t work.

    My main calendar page shows just the site name: http://thorntonandlowe.com/training/
    Calendar view shows Site name > The Events Calendar (but Sitename isn’t even a link): http://thorntonandlowe.com/training/
    Course categories show just a site name: http://thorntonandlowe.com/training/category/bid-writing-course/
    Venue shows just a site name but also 2 separators (» »): http://thorntonandlowe.com/venue/london/
    Event listing is the same as above. Site name plus 2 separators (» »): http://thorntonandlowe.com/course/bid-writing-course-birmingham/

    Please help, I’ve spent so many long frustrating hours and days on this I have to resolve it to make them all worthwhile.

    Thanks in advance.

    #1067927
    Nico
    Member

    Hey Shaun,

    Thanks for reaching out on this, and please don’t panic! I’m here to help 🙂

    Please let me know what you expect the breadcrumb to show for each view and I’ll adjust the tribe_breadcrumbs function to show that. Note view + desired result (linked or not).

    For example:
    – Main Calendar: Site Name (linked).
    – Single Event: Site Name (linked) > Calendar (linked) > Event Category (linked) > Event Name (not linked).

    Thanks,
    Nico

    #1068002
    Shaun
    Participant

    Hi Nico,

    Thanks for offering to help, it’s very much appreciated.

    I don’t tink Site name is required on any view really. But, if it’s possible to have a page that isn’t actually part of the Calendar plugin as the first breadcrumb that would be great. As this page – http://thorntonandlowe.com/services/bid-tender-training/ – is essentially the starting point, rather than the plugin main view (I did this because I needed custom content on the page). It uses the same page template as the plugin.

    So all pages would start with ‘Bid/Tender Training’ (linked) and the different views would look like this:

    Main calendar: ‘Bid/Tender Training’ (linked) > Calendar (not linked) (if possible)
    Single Event: ‘Bid/Tender Training’ (linked) > Event Category (linked) > Event Name (not linked)
    Event Category: ‘Bid/Tender Training’ (linked) > Event Category (not linked)
    Venue View: ‘Bid/Tender Training’ (linked) > Venue name (not linked)

    I’m not sure if all of the above it definitely possible. If not, I’m happy to compromise and just get as close as it can be. Just some form of working breadcrumbs would be great.

    Thanks again for your help.

    #1069802
    Nico
    Member

    This reply is private.

    #1070900
    Nico
    Member

    Hey Shaun,

    Thanks for the patience on this 🙂

    I’ve modified the snippet to work as you described:


    // Check if page is direct child
    function is_child( $page_id ) {
    global $post;
    if( is_page() && ($post->post_parent != '') ) {
    return true;
    } else {
    return false;
    }
    }

    // Breadcrumb Logic
    function tribe_breadcrumbs() {
    global $post;

    $separator = " » ";

    echo '

    ';
    echo 'Bid/Tender Training';

    if( (tribe_is_list_view() || tribe_is_month()) && !is_tax() ) { // The Main Calendar Page
    echo $separator;
    echo 'Calendar';
    } elseif( (tribe_is_list_view() || tribe_is_month()) && is_tax() ) { // Calendar Category Pages

    global $wp_query;
    $term_slug = $wp_query->query_vars['tribe_events_cat'];
    $term = get_term_by('slug', $term_slug, 'tribe_events_cat');
    get_term( $term_id, 'tribe_events_cat' );
    $name = $term->name;

    echo $separator;
    echo $name;
    } elseif( tribe_is_event() && !tribe_is_day() && !is_single() ) { // The Main Events List
    echo $separator;
    echo 'Events List';
    } elseif( tribe_is_event() && is_single() ) { // Single Events

    if ( $terms = get_the_terms( $post->ID, 'tribe_events_cat' ) ) {
    $term = array_pop($terms);
    echo $separator;
    echo 'slug, 'tribe_events_cat').'">'.$term->name.'';
    }

    echo $separator;
    the_title();
    } elseif( tribe_is_day() ) { // Single Event Days
    global $wp_query;

    echo $separator;
    echo 'Events';
    echo $separator;
    echo 'Events on: ' . date('F j, Y', strtotime( $wp_query->query_vars['eventDate']) );
    } elseif( tribe_is_venue() ) { // Single Venues
    echo $separator;
    the_title();
    } elseif ( is_category() || is_single() ) {
    echo $separator;
    the_category(' • ');

    if ( is_single() ) {
    echo ' '.$separator.' ';
    the_title();
    }
    } elseif ( is_page() ) {
    if( is_child(get_the_ID()) ) {
    echo $separator;
    echo 'post_parent ) . '">' . get_the_title( $post->post_parent ) . '';
    echo $separator;
    echo the_title();
    } else {
    echo $separator;
    echo the_title();
    }
    } elseif (is_search()) {
    echo $separator.'Search Results for... ';
    echo '"';
    echo the_search_query();
    echo '
    "';
    }
    echo '

    ';
    }

    Please let me know about it,
    Best,
    Nico

    #1070922
    Shaun
    Participant

    Hi Nico,

    Firstly, thank you so much for your ongoing help with this, I really do appreciate it.

    However, unfortunately, the code still doesn’t seem to work.

    Initially, there were a couple of syntax errors thrown out. I’m no PHP expert but I think I sorted them out.

    It was lines 41 & 67 from your code above.

    Here’s the code with the changes I made:

    // Check if page is direct child
    function is_child( $page_id ) {
            global $post;
            if( is_page() && ($post->post_parent != '') ) {
                    return true;
            } else {
                    return false;
            }
    }
    
    // Breadcrumb Logic
    function tribe_breadcrumbs() {
            global $post;
    
            $separator = " » ";
    
            echo '<div class="tribe-breadcrumbs">';
            echo 'Bid/Tender Training';
    
            if( (tribe_is_list_view() || tribe_is_month()) && !is_tax() ) { // The Main Calendar Page
                    echo $separator;
                    echo 'Calendar';
            } elseif( (tribe_is_list_view() || tribe_is_month()) && is_tax() ) { // Calendar Category Pages
    
                    global $wp_;
                    $term_slug = $wp_->_vars['tribe_events_cat'];
                    $term = get_term_by('slug', $term_slug, 'tribe_events_cat');
                    get_term( $term_id, 'tribe_events_cat' );
                    $name = $term->name;
    
                    echo $separator;
                    echo $name;
            } elseif( tribe_is_event() && !tribe_is_day() && !is_single() ) { // The Main Events List
                    echo $separator;
                    echo 'Events List';
            } elseif( tribe_is_event() && is_single() ) { // Single Events
    
                    if ( $terms = get_the_terms( $post->ID, 'tribe_events_cat' ) ) {
                            $term = array_pop($terms);
                            echo $separator;
                            echo 'slug', 'tribe_events_cat'.'">'.$term->name.'';
                    }
    
                    echo $separator;
                    the_title();
            } elseif( tribe_is_day() ) { // Single Event Days
                    global $wp_;
    
                    echo $separator;
                    echo 'Events';
                    echo $separator;
                    echo 'Events on: ' . date('F j, Y', strtotime( $wp_->_vars['eventDate']) );
            } elseif( tribe_is_venue() ) { // Single Venues
                    echo $separator;
                    the_title();
            } elseif ( is_category() || is_single() ) {
                    echo $separator;
                    the_category(' • ');
    
                    if ( is_single() ) {
                            echo ' '.$separator.' ';
                            the_title();
                    }
            } elseif ( is_page() ) {
                    if( is_child(get_the_ID()) ) {
                            echo $separator;
                            echo 'post_parent' . '">' . get_the_title( $post->post_parent ) . '';
                            echo $separator;
                            echo the_title();
                    } else {
                            echo $separator;
                            echo the_title();
                    }
            } elseif (is_search()) {
                    echo $separator.'Search Results for... ';
                    echo '"';
                    echo the_search_();
                    echo '"';
            }
            echo '</div>';
    }

    The calendar page is almost right – http://thorntonandlowe.com/training/month/ -. It shows the right text (Bid & Tender Training > Calendar) but the first item isn’t a link.

    But the other pages, whether is’s a category view – http://thorntonandlowe.com/training/category/bid-writing-course/ – or Venue view – http://thorntonandlowe.com/venue/manchester/ – just show ‘Bid/Tender Training’ but again not linked.

    That page itself (Bid & Tender Training) is the most interesting, it shows: Bid/Tender Training » post_parent”>Services » Bid & Tender Training – but again no links. http://thorntonandlowe.com/services/bid-tender-training/

    Hopefully it’s just a minor tweak to the code required, or perhaps it is due to those syntax errors and I didn’t actually fix them properly?

    Thanks again,

    Shaun

    #1071720
    Nico
    Member

    Hey Shaun,

    Thanks for following up on this! Good catches on the PHP errors, I forgot that sometimes pasting snippets in the editor is not best idea as in this case some tags get omitted/converted.

    Please try again with the same original snippet:

    https://gist.github.com/niconerd/0a46d2e6e3ccd70ed29e

    This is working correctly in local install, also linking the first part. I’ve removed a bit the code for search, pages and day view as you don’t seem to need that.

    Let me know if it works as expected now!

    Best,
    Nico

    #1071871
    Shaun
    Participant

    Hi Nico.

    Thanks again for your support. We’re almost there now but there’s still something not quite right.

    The root link is working properly on all pages (i.e linking to the Bid/Tender Training page) and the next part of the breadcrumb is correct for the root page, calendar and category lists.

    But the venue list pages – http://thorntonandlowe.com/venue/manchester/ – and single event page – http://thorntonandlowe.com/course/nhs-specific-manchester/ – only show the root link and nothing else.

    Sorry to be a pain, but I’d really appreciate your help to get these last 2 bits sorted now that we’re so close.

    Thanks again.

    #1073380
    Nico
    Member

    Hey Shaun,

    Don’t worry we will continue to work on this until it’s working for you 🙂

    I’ve just re-checked on my local install and it’s working as expected, so not sure what can be causing this… Can you please try to switch to TwentyFifteen default theme and de-activate all other plugins but The Events Calendar? And of course be sure to move the code to the theme’s functions.php file and also to move the template override of the default events template to the theme folder. Under this conditions it’s working fine for me. You can also re-paste the snippet from the Gist to make sure it’s correctly in place.

    Please let me know about it,
    Best,
    Nico

    #1073856
    Shaun
    Participant

    I tested the current theme with all other plugins removed but the problem remained.

    I then tested in TwentyFifteen as you suggested and the breadcrumbs do indeed work as expected. With all current plugins still enabled too.

    So there is clearly something within the theme causing the issue.

    I’ve tried removing everything else from functions.php (there was some other stuff I’ve picked up from your forum to do various bits to the calendar like change the slugs etc.. that I thought may be conflicting) but no joy.

    I can’t think of anything else theme based that could be causing the problem so hopefully you have more of an idea?

    Thanks

    #1074468
    Nico
    Member

    Hey Shaun,

    Thanks for confirming this! What I’ve seen that suggested this might be a theme issue was that in the venue and single event pages I noticed a <div id="post-0"> tag, so maybe the post global var is being re-set or manipulated somewhere. Can you reach the theme author on this?

    Best,
    Nico

    #1074471
    Shaun
    Participant

    Hi Nico,

    I don’t think that is the problem as I’ve spent a long time on this today.

    After some painstaking trial & error I have figured out what is causing this but I have no idea why and hope that you can find a better solution than I have.

    So for some bizarre reason the breadcrumbs only work on the venue and single category view if get_sidebar(); is present ABOVE the tribe_breadcrumbs(); function in the template!

    They don’t work without get_sidebar(); and they don’t even work if get_sidebar(); is below the tribe_breadcrumbs(); call.

    I have no idea why this would be. At the moment I’ve left get_sidebar(); in the code but hidden with CSS so the breadcrumbs display correctly but obviously it means I have lots of unnecessary HTML code being generated that really shouldn’t be there.

    Do you have any idea why this may be?

    #1074833
    Nico
    Member

    Hey Shaun,

    Great catch! I have absolutely no idea what can be causing this. Maybe it’s a specific widget code that makes it works? You can try to disable the widgets one by one to get more info on this, or maybe it’s some code on the sidebar.php file that makes it work?

    ¯\_(ツ)_/¯

    As the original breadcrumb issue has been addressed, Do you think we are good to close out this thread?

    Please let me know about it,
    Best,
    Nico

    #1077922
    Shaun
    Participant

    Hi Nico,

    I’ve not had much luck figuring out what it is from the sidebar code making the breadcrumbs work.

    But since the breadcrumbs are now working then sure, feel free to close the thread.

    Thanks for your help with this.

    #1078546
    Nico
    Member

    Hey Shaun,

    Thanks for confirming we are good here, and sorry for not being able to help you further. If the theme you use is crafted by another dev or company be sure to reach out to them. If you coded it, be sure to check how default WordPress theme is doing the sidebar inclusion, etc. Default themes are usually great places to sneak on best practices.

    I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.

    Have a great weekend,
    Nico

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Major issue with breadcrumbs’ is closed to new replies.