Home › Forums › Calendar Products › Community Events › Displaying a Class Name for Past Events Only
- This topic has 2 replies, 3 voices, and was last updated 8 years, 2 months ago by Support Droid.
-
AuthorPosts
-
February 8, 2016 at 9:12 am #1069590DwayneParticipant
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!
February 11, 2016 at 6:51 pm #1071803GeorgeParticipantHey @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!
GeorgeFebruary 26, 2016 at 8:35 am #1082470Support 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 ‘Displaying a Class Name for Past Events Only’ is closed to new replies.