Different style depending on category

Home Forums Calendar Products Events Calendar PRO Different style depending on category

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1027129
    Rosa Maria
    Participant

    Hi,

    I want to apply a different style to events depending on the category. I have follow your answer of the topic ” https://theeventscalendar.com/support/forums/topic/different-styles-in-month-overview-depending-on-category-or-how-to-enter-custom/ “. But all I get is the category class added in all the pages, but not in events. The Events Single View don’t has the category added to the body (only appears “category-“). How can I fix it?

    Thanks for your help

    #1027175
    Brian
    Keymaster

    Hi,

    Thanks for using our plugins. I can try to help out here.

    Did you already start some coding to do this and can you share it?

    Let me know and we can go from here.

    Thanks

    #1027848
    Rosa Maria
    Participant

    Hi Brian,

    I have added this code to functions.php:

    function add_category_name($classes = '') {
       if(is_single()) {
          $category = get_the_category();
          $classes[] = 'category-'.$category[0]->slug; 
       }
       return $classes;
    }
    add_filter('body_class','add_category_name');
    #1027878
    Brian
    Keymaster

    Hi,

    That coding is on the right track, but the event categories are a custom taxonomy so it will not work with get_the_category().

    I came up with this coding instead and it worked for me:

    /*
    * The Events Calendar - Add First Event Category Name to Body Class in Single Events
    *
    * Events > Settings > Display Tab > Events Template must be set to Default Event Template
    */
    add_filter( 'body_class', 'tribe_add_event_category' );
    function tribe_add_event_category( $classes = '' ) {

    global $post;

    if ( is_singular( 'tribe_events' ) ) {

    $category = get_the_terms( $post->ID, 'tribe_events_cat' );

    $classes[] = 'category-' . $category[0]->slug;

    }

    return $classes;
    }

    This will only work if this Events template setting here:

    Events > Settings > Display Tab > Events Template

    Is set to “Default Events Template”

    Cheers

    #1028169
    Rosa Maria
    Participant

    Hi,

    But my Events Template is set to “Default Page Template”… Which code must I use, then? How can I fix it?

    Cheers

    #1028180
    Brian
    Keymaster

    You can try this coding from George, that might work:

    https://theeventscalendar.com/support/forums/topic/add-category-name-as-body_class/#dl_post-1023203

    Beyond that I do not have anything else to provide on this and can only support existing features and not customizations.

    Thanks

    #1075710
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Different style depending on category’ is closed to new replies.