trail for event category and events page

3 Replies ·

  1. I have left this site
    https://turkeybeach.org.au
    open if you need to see what I am talking about, but it is only at the testing stage, and using a child theme of Stargazer.

    Permalinks are set to /%category%/%postname%/

    I use an events plugin
    https://wordpress.org/plugins/very-simple-event-list/

    On the events page
    https://turkeybeach.org.au/event/
    the breadcrumb is Home(icon) > Events

    Clicking the event on that page takes one to
    https://turkeybeach.org.au/event/test/
    and breadcrumb trail is Home > Events(links to Events page) > Test

    All fine. However, going to the category page ‘tester’,
    (https://turkeybeach.org.au/event_cat/tester/)
    the breadcrumb trail is Home(icon) > Events(link, but just reloads page) > tester

    This is bound to confuse some users.
    Can you suggest a fix?
    thanks

  2. Justin Tadlock

    It looks like your plugin isn’t setting up a proper post type archive or giving you a nice rewrite structure. Ideally, this should be set up better.

    But, there is a bug in the breadcrumbs code too. Honestly, there are two ways to fix this.

    1. Have you change code some directly in the breadcrumbs script, but it’s a bit of a hack.
    2. Or, we just filter this and make the breadcrumbs nice.

    The first option will give you Home > Event Category (which is correct based on how the events plugin is built. The second option, which I’m posting the code for below will give you Home > Events > Event Category.

    Add this code to your theme’s functions.php:

    add_filter( 'breadcrumb_trail_items', 'th_breadcrumb_items' );
    
    function th_breadcrumb_items( $items ) {
    
        if ( is_tax( 'event_cat' ) ) {
    
            $items = array();
            $term  = get_queried_object();
    
            $items[] = sprintf( '<a href="%s">Home</a>', esc_url( user_trailingslashit( home_url() ) ) );
    
            $items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( 51 ) ), esc_html( get_the_title( 51 ) ) );
    
            if ( is_paged() ) {
    
                $items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $term, $term->taxonomy ) ), single_term_title( '', false ) );
    
                $items[] = sprintf( $this->labels['paged'], number_format_i18n( absint( get_query_var( 'paged' ) ) ) );
    
            } else {
    
                $items[] = single_term_title( '', false );
            }
        }
    
        return $items;
    }
    
  3. markmcl

    isn’t setting up a proper post type archive or giving you a nice rewrite structure

    I did a fair bit of reading before posting my question and thought that the plugin may be lacking slug=>event-category for the taxonomy

    and if so would have been able to use {$permastruct}_rewrite_rules

    Was I anywhere near the mark, & is the plugin missing something else/other?

  4. Justin Tadlock

    Generally speaking, I’d default my permalinks for a CPT and CT plugin to something like (using the slug parameter):

    yoursite.com/events (CPT archive)
    yoursite.com/events/slug (single CPT post)
    yoursite.com/events/categories/slug (CT archive)
    

    This can all be done when registering the post type and taxonomy via register_post_type() and register_taxonomy().

    Then, give users the option to change those like in my Custom Content Portfolio plugin:

    Custom Content Portfolio screenshot