Skip to content

Instantly share code, notes, and snippets.

@jesseeproductions
Last active October 13, 2023 14:22
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jesseeproductions/903f5ca75877b713c674 to your computer and use it in GitHub Desktop.
Save jesseeproductions/903f5ca75877b713c674 to your computer and use it in GitHub Desktop.
The Events Calendar Conditionals
/*-----------------------------------------------------------------------------------*/
/* The Events Calendar - Conditional Logic to Detect Various Event Related Views/Pages
/*-----------------------------------------------------------------------------------*/
if ( tribe_is_month() && ! is_tax() ) { // Month View Page
echo 'were on the month view page';
} elseif ( tribe_is_month() && is_tax() ) { // Month View Category Page
echo 'were on the month view category page';
} elseif ( tribe_is_past() || tribe_is_upcoming() && ! is_tax() ) { // List View Page
echo 'were on the list view page';
} elseif ( tribe_is_past() || tribe_is_upcoming() && is_tax() ) { // List View Category Page
echo 'were on an list view category page';
} elseif ( tribe_is_week() && ! is_tax() ) { // Week View Page
echo 'were the week view page';
} elseif ( tribe_is_week() && is_tax() ) { // Week View Category Page
echo 'were the week view category page';
} elseif ( tribe_is_day() && ! is_tax() ) { // Day View Page
echo 'were on the day view page';
} elseif ( tribe_is_day() && is_tax() ) { // Day View Category Page
echo 'were on a day view category page';
} elseif ( tribe_is_map() && ! is_tax() ) { // Map View Page
echo 'were on the map view page';
} elseif ( tribe_is_map() && is_tax() ) { // Map View Category Page
echo 'were on the map view category page';
} elseif ( tribe_is_photo() && ! is_tax() ) { // Photo View Page
echo 'were on the photo view page';
} elseif ( tribe_is_photo() && is_tax() ) { // Photo View Category Page
echo 'were on the photo view category page';
} elseif ( tribe_is_event() && is_single() ) { // Single Events
echo 'were on a single event page';
} elseif ( tribe_is_venue() ) { // Single Venues
echo 'were on a single venue page';
} elseif ( get_post_type() == 'tribe_organizer' && is_single() ) { // Single Organizers
echo 'were on a single organizer page';
} else {
}
//Get Main Views in Pro only if Core and Pro Active
if ( class_exists( 'Tribe__Events__Main' ) && class_exists( 'Tribe__Events__Pro__Main' ) ) {
if ( tribe_is_month() || tribe_is_upcoming() || tribe_is_past() || tribe_is_day() || tribe_is_map() || tribe_is_photo() || tribe_is_week() ) {
//All Event Views
}
//Get Main Views in Core if Core is Active and Pro is Not
} elseif ( class_exists( 'Tribe__Events__Main' ) && ! class_exists( 'Tribe__Events__Pro__Main' ) ) {
if ( tribe_is_month() || tribe_is_upcoming() || tribe_is_past() || tribe_is_day() ) {
//Core Event Views Only
}
}
//If Tribe Events View or Single Template
if ( tribe_is_event() || tribe_is_event_category() || tribe_is_in_main_loop() || tribe_is_view() || 'tribe_events' == get_post_type() || is_singular( 'tribe_events' ) ) {
//Do something if it's a Tribe Events Page
} else {
//Do something else if it's not a Tribe Events page
}
/**
* Community Events
*
*/
//Community Events List Page
tribe_is_community_my_events_page()
//Community Events Edit Form
tribe_is_community_edit_event_page()
/**
* More Conditionals
*
*/
tribe_is_ajax_view_request()
tribe_is_recurring_event()
tribe_is_event_category()
tribe_is_bot()
tribe_is_new_event_day()
tribe_is_past()
tribe_is_by_date()
tribe_is_in_main_loop()
tribe_is_event_organizer()
tribe_is_event_venue()
tribe_is_event_query()
tribe_is_view()
tribe_is_event()
@hansschuijff
Copy link

Hi Jessee,

Thanks for the conditionals. Great help! Hope you or someone will answer the below questions about it. I'm just someone that wants to customize my theme, so not a php buff.

I wonder why you sometimes explicitly check for the availability of the plugins by first checking class_exists( 'Tribe__Events__Main' ) and/or class_exists( 'Tribe__Events__Pro__Main' ) and other times not... Will the function calls tot the tribe_is_... function otherwise generate error-messages? And if so, why should that check not always be done first? I'm not sure how php handles the non-existence of a function when it's called, but remember in some theme I had to generate a dummy function just to cope with the fact that I didn't want a plugin installed while the theme called a function that was part of it.

The class_exists conditionals are put in a separate if-statement. Is there a technical reason for not combining the ifs or would nothing change when they are combined?

Would the condition ( singular ('tribe_organizer') ) be equal to ( get_post_type() == 'tribe_organizer' && is_single() ) or is there a reasons to split it like this (perhaps efficiency?) ?

Just trying to understand and learn. Thanks, Hans

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment