Displaying a Class Name for Past Events Only

Home Forums Calendar Products Community Events Displaying a Class Name for Past Events Only

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1069590
    Dwayne
    Participant

    Hello,

    On my site, I am showing users an option to see upcoming events by category AND past events by category.

    For the Past Events category, I am appending “?tribe_event_display=past” to the URL. This works great for filtering the events.

    However, I would like to be able to append a class name such as “past-events” to the site container, or body tag. Is there a method for doing this, where any page with “?tribe_event_display=past” in the URL can generate this extra class name?

    Thanks!

    #1071803
    George
    Participant

    Hey @Dwayne,

    I’m really sorry for the delayed reply here! Especially for the fact that I have to bear some bad news within it. I’ve tried numerous custom coding attempts to try and pull this off, but unfortunately it does not work consistently.

    The best solution I’ve been able to assemble is this one:


    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';
    }
    }

    return $classes;
    }

    Try pasting that into your theme’s functions.php file – this will add a class name to the site body tag of tribe-is-past, so you could then write CSS like this:


    body.tribe-is-past {
    // custom styles when viewing events in the past
    }

    I hope that this is helpful! Please let me know if so, and if there’s anything else I can help with.

    Thank you!
    George

    #1082470
    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 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Displaying a Class Name for Past Events Only’ is closed to new replies.