• Resolved fl0ri

    (@fl0ri)


    Hi there! I want to add a body class to the single event view if the event is a past event. My code (in functions.php) reads like:

    add_filter( 'body_class','my_body_classes' );
        function my_body_classes( $classes ) {
    
            if( tribe_is_past() ) {
    
                $classes[] = 'past-event';
    
            }
    
            return $classes;
    
        }

    But it doesn’t work. Any suggestions?

    https://wordpress.org/plugins/the-events-calendar/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter fl0ri

    (@fl0ri)

    Anyone? I still have no idea how to solve this since The Events Calendar does not work with categories in terms of upcoming and past, but with the field EventDisplay, which I cannot handle. So if you happen to have an idea on how to add a body class “past-event” to the single view of past events, please let me know.

    Thread Starter fl0ri

    (@fl0ri)

    I did find an approach to solve this here:
    https://theeventscalendar.com/support/forums/topic/displaying-a-class-name-for-past-events-only/

    Unfortunately it’s not working (any more?).
    Also I would like to extend the function as follows:

    /* Adds new body class for past event */
    add_filter( 'body_class', 'tribe_events_past_events_body_class' );
    
    function tribe_events_past_events_body_class( $classes ) {
    
        global $wp_query;
    
        $event_date = get_query_var( 'eventDate' );
    
        if ( isset( $event_date ) ) {
    
            $this_month = current_time( 'Y-m' );
            $is_past    = strtotime( $event_date ) < strtotime( $this_month );
    
            if ( $is_past ) {
                $classes[] = 'tribe-is-past';
            }
            else {
                $classes[] = 'tribe-is-upcoming';
            }
        }
    
        return $classes;
    }

    But in any case, neither the original code from the forum nor the modified one work.
    Does someone have an idea?

    Thread Starter fl0ri

    (@fl0ri)

    Seriously? Nobody?

    Sean Hayes

    (@seanchayes)

    I managed to put something together that adds a class to the body if the event has passed.

    Here’s a Gist of it:
    Add body class “past-event” to single event view

    I hope that helps

    Thread Starter fl0ri

    (@fl0ri)

    Sean! Thank you! This really is working. Great job!

    nicosantos

    (@nicosantos)

    Hey Sean,

    Thanks for helping out once again 🙂

    We really appreciate it!

    Best,
    Nico

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add body class "past-event" to single event view’ is closed to new replies.