Home › Forums › Calendar Products › Events Calendar PRO › Different style depending on category
- This topic has 6 replies, 3 voices, and was last updated 8 years, 3 months ago by Support Droid.
-
AuthorPosts
-
November 17, 2015 at 12:15 pm #1027129Rosa MariaParticipant
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
November 17, 2015 at 2:25 pm #1027175BrianKeymasterHi,
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
November 19, 2015 at 1:57 am #1027848Rosa MariaParticipantHi 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');
November 19, 2015 at 5:09 am #1027878BrianKeymasterHi,
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
November 19, 2015 at 9:47 am #1028169Rosa MariaParticipantHi,
But my Events Template is set to “Default Page Template”… Which code must I use, then? How can I fix it?
Cheers
November 19, 2015 at 10:31 am #1028180BrianKeymasterYou 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
February 18, 2016 at 8:31 am #1075710Support DroidKeymasterThis 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. -
AuthorPosts
- The topic ‘Different style depending on category’ is closed to new replies.