Posted: March 11, 2015 at 10:21 pm
|
Hi, How would I set a container elements class with an the events categories? For example: <article class=”my-event-category”> Thanks, |
|
Hi, If your theme is using post_class() to add classes to the Article tag, then you can use a filter, see here: http://codex.wordpress.org/Function_Reference/post_class#Add_Classes_By_Filters Please note that Event Categories are in fact Custom Taxonomies (the slug is espresso_event_category). |
|
So to clarify if I add a function like this to add the classes I’ll have to use the slug: ‘espresso_event_category’? Where in the function should that go?
|
Hi, are you referring to something like this? https://eventespresso.com/wiki/useful-php-code-snippets/#category-css Sample code snippets can be added to your child theme’s functions.php file (do not include the opening php tag) or a site specific plugin: https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/ — |
|
|
Thanks. That’s handy. Can they also be added to the body? |
|
Alright. I’ve sussed that one out. Here’s how I’ve added the EE taxonomy to the body class. With help from this post: https://wordpress.org/support/topic/style-taxonomy-posts?replies=3#post-2815963
|
|
No my next issue is that I need the taxonomy to carry through to the body class on the registration pages. Any ideas? |
Hi there, That’s kind of tricky because the registration page does not have direct access to the event object. This is because the registration checkout process, which we call Single Page Checkout internally, is designed to accommodate more than one event. I got some help from one of the developers who showed me how to get the event object from the transaction in progress. Here’s an example that works in a few methods to get the event category slug. function jf_ee_return_event_tax_term_on_spco( $classes ){ // get out if this isn't the reg checkout page if (! is_page( 'registration-checkout' ) ){ return $classes; } $events = array(); $checkout = EE_Registry::instance()->SSN->checkout(); if ( $checkout instanceof EE_Checkout ) { $transaction = $checkout->transaction; if ( $transaction instanceof EE_Transaction ) { foreach ( $transaction->registrations() as $registration ) { if ( $registration instanceof EE_Registration ) { $event = $registration->event(); if ( $event instanceof EE_Event ) { $events[ $event->ID() ] = $event; $classes[] = $event->first_event_category()->slug(); } } } } } return $classes; } add_filter( 'body_class', 'jf_ee_return_event_tax_term_on_spco' ); You’ll note that there’s a method that’s used in there to grab the first event category in case there’s more than one category assigned to the event. |
|
A little update on the above code idea: One more check would be good in case an event doesn’t have any categories assigned to it: function jf_ee_return_event_tax_term_on_spco( $classes ){ // get out if this isn't the reg checkout page if (! is_page( 'registration-checkout' ) ){ return $classes; } $events = array(); $checkout = EE_Registry::instance()->SSN->checkout(); if ( $checkout instanceof EE_Checkout ) { $transaction = $checkout->transaction; if ( $transaction instanceof EE_Transaction ) { foreach ( $transaction->registrations() as $registration ) { if ( $registration instanceof EE_Registration ) { $event = $registration->event(); if ( $event instanceof EE_Event ) { $events[ $event->ID() ] = $event; $category = $event->first_event_category(); if ( $category instanceof EE_Term ) { $category_slug = $category->slug(); $classes[] = $category_slug; } } } } } } return $classes; } |
|
The support post ‘Set EE4 categories as class’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.