Support

Home Forums Event Espresso Premium Sanity check on a body_class filter

Sanity check on a body_class filter

Posted: August 19, 2016 at 12:04 am

Viewing 5 reply threads


nyingma

August 19, 2016 at 12:04 am

If I could impose, I would like your professional opinion on my approach to a body_class filter. Use case: we record some of our events (classes) and I have a “Recording Calendar” where I am displaying expired events with a venue of “Recording” and the video in the description. All good so far.

I am using the Divi theme and it sets a body class of “et_right_sidebar”, which is great for upcoming events so I can display the cart widget, but I would like to change the class to “et_full_width_page” for the recorded events so the video is full width. Here is the code I came up with for the filter for your entertainment. Suggestions and criticism requested.

add_filter('body_class', 'divi_child_body_classes', 20);
function divi_child_body_classes($classes) {
    global $post;

    if ($post->post_type == 'espresso_events') {
        $venues = EEH_Venue_View::get_event_venues();
        $venues = is_array($venues) ? $venues : array();
        foreach ($venues as $venue) {
            if ($venue instanceof EE_Venue) {
                if (strpos((EEH_Venue_View::venue_name('none', $venue->ID())), 'Recording') !== false) {
                    $key = array_search('et_right_sidebar', $classes);
                    if (!empty($key)) {
                        unset($classes[$key]);
                    }
                    $classes[] = 'et_full_width_page';
                    break;
                }
            }
        }
    }
    return $classes;
}

Thank you in advance for your indulgence.


Tony

  • Support Staff

August 19, 2016 at 5:14 am

Hi there,

What you have above should work fine but can I ask why you are using a Venue for this rather than a category?


nyingma

August 19, 2016 at 12:17 pm

Hi Tony,

Thanks for the feedback!

That was my initial approach; however, we also use categories to organize our classes: Meditation, Tibetan Yoga, etc., and I want to keep the option of adding the category filter to the calendar (will have to disable the display of the venue filter) which is a little confusing when you add “Recording” to the list.

So that was the rational…such as it is.

Thanks again for your time.

Cheers,

Mark


Josh

  • Support Staff

August 19, 2016 at 2:06 pm

Hi Mark,

You could also use the tags taxonomy to classify the “Recording” events. This way you can use the venues for their intended purpose.


nyingma

August 19, 2016 at 3:19 pm

Hey Josh,

I looked into that as well but if memory serves the calendar shortcodes did/do not allow to filter on tags.

I’m comfortable designating venue to this purpose since we only have three classrooms and what’s where is a bit on the fluid side; I’d rather not parade our indecision….

I really appreciate the feedback!

Cheers,

Mark


Josh

  • Support Staff

August 19, 2016 at 4:04 pm

You’re welcome.

Viewing 5 reply threads

The support post ‘Sanity check on a body_class filter’ 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.

Event Espresso