-
-
Save jo-snips/2415009 to your computer and use it in GitHub Desktop.
<?php | |
/*-----------------------------------------------------------------------------------*/ | |
/* 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 { | |
} |
Is there a way to do this without having to manually specify actions for each page type?
Such as:
} 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';
get_post_type() == 'tribe_organizer' && is_single()
should do the same as is_singular('tribe_organizer')
Is there a conditional to test for venue? I want to automatically display an image of one of several venues if that venue is selected for an event.
Works like a charm to me. Sometimes it could be useful to output a line of text to see where we exactly are, so here you go:
// check if on tribe calendar page
public static function is_tribe_page($debug = false){
$is_tribe_page = false;
if( tribe_is_month() && !is_tax() ) { // Month View Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar the month view page</p>'; }
} elseif( tribe_is_month() && is_tax() ) { // Month View Category Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar the month view category page</p>'; }
} elseif( tribe_is_past() || tribe_is_upcoming() && !is_tax() ) { // List View Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar the list view page</p>'; }
} elseif( tribe_is_past() || tribe_is_upcoming() && is_tax() ) { // List View Category Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar an list view category page</p>'; }
} elseif( tribe_is_week() && !is_tax() ) { // Week View Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar the week view page</p>'; }
} elseif( tribe_is_week() && is_tax() ) { // Week View Category Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar the week view category page</p>'; }
} elseif( tribe_is_day() && !is_tax() ) { // Day View Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar the day view page</p>'; }
} elseif( tribe_is_day() && is_tax() ) { // Day View Category Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar a day view category page</p>'; }
} elseif( tribe_is_map() && !is_tax() ) { // Map View Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar the map view page</p>'; }
} elseif( tribe_is_map() && is_tax() ) { // Map View Category Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar the map view category page</p>'; }
} elseif( tribe_is_photo() && !is_tax() ) { // Photo View Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar the photo view page</p>'; }
} elseif( tribe_is_photo() && is_tax() ) { // Photo View Category Page
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar the photo view category page</p>'; }
} elseif( tribe_is_event() && is_single() ) { // Single Events
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar a single event page</p>'; }
} elseif( tribe_is_venue() ) { // Single Venues
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar a single venue page</p>'; }
} elseif( get_post_type() == 'tribe_organizer' && is_single() ) { // Single Organizers
$is_tribe_page = true;
if($debug){ echo '<p class="tribe_page_debug">Tribe calendar a single organizer page</p>'; }
} else {
if($debug){ echo '<p class="tribe_page_debug">Not a tribe calendar page</p>'; }
}
return $is_tribe_page;
}
Thanks for the conditionals! I would have hoped conditionals for targeting all tribe pages at once or all calendar views at once and more would be part of the plugin, but this helps and solves the missing conditionals of the plugin.
Strange the is_tribe_organizer() is missing, since all other detail pages seem to have their own conditional.
In a lot of code snippets I also saw a wrapper if-statement testing on class_exists() for either tec or tec pro. Will the above code generate errors or warnings if the plugins are not installed?
There really should be an all encompassing is_tribe() or tribe_is() conditional tag.
For instance I'd like to have a plugin that says if this is "any" calendar item then do something.
As an example, I use a web governance SaaS that loves to charge by number of pages on a site and would like to exclude all calendar pages along with some other generated pages that don't need to be inspected.
add_action( 'wp_footer', 'my_footer_scripts' );
function my_footer_scripts(){
// Load script for home, pages, single posts except calendar pages and attachment posts.
if ( is_page() || is_home() || is_single() && ( ! ( is_attachment() || tribe_is() ) ) ) {
echo 'script loaded';
} else {
echo 'script not loaded';
// Don't load script
}
}
As a response to myself this will work. However, fewer checks would be ideal.
add_action( 'wp_footer', 'my_footer_scripts' );
function my_footer_scripts(){
// Load script for home, pages, single posts. Exclude all types of calendar pages and attachment posts.
if ( is_page() || is_home() || is_single() && ( ! ( is_attachment() || tribe_is_month() || tribe_is_past() || tribe_is_week() || tribe_is_day() || tribe_is_map || tribe_is_photo() || tribe_is_event() || tribe_is_venue() || get_post_type() == 'tribe_organizer' && is_single() ) ) ) {
echo 'script loaded';
} else {
echo 'script not loaded';
// Don't load script
}
}
Haven't tested it, but wouldn't something like this work?
function prefix_tribe_is() {
if ( class_exists( 'Tribe__Events__Main' ) ) {
return null !== Tribe__Events__Main::instance()->displaying ? true : false;
}
}
I have tried your code out, but i'm not seeing the desired results. Here is the full contents of the navigation.php that contains all the breadcrumb code. Can you see what might be wrong? Thank you Jonah.
'nav_menu_item', 'numberposts' => -1, 'meta_query' => array( array( 'key' => '_menu_item_url', 'value' => $dev_home_url, 'compare' => 'LIKE' ) ) ) ); // Loop 'em to change foreach( $posts as $post ) { // Get URL $url = get_post_meta( $post->ID, '_menu_item_url', true ); // Change it to this install's home URL $new_url = str_replace( $dev_home_url, $home_url, $url ); update_post_meta( $post->ID, '_menu_item_url', esc_url_raw( $new_url ) ); // Debug //echo "\n\n$url\n$new_url\n"; //print_r( $post ); } } ``` } /********************************** - BREADCRUMB **********************************/ /** - Output breadcrumb path */ if ( ! function_exists( 'risen_breadcrumbs' ) ) { ``` function risen_breadcrumbs() { global $post; // Enabled in Theme Options if ( risen_option( 'breadcrumbs' ) ) { $breadcrumbs = array(); // Page if ( is_page() ) { // Get page and parents if any $breadcrumbs = array_merge( $breadcrumbs, risen_page_breadcrumbs( $post->ID ) ); } // Multimedia (post, category, speaker, tag, date archives) else if ( is_singular( 'risen_multimedia' ) || is_tax( 'risen_multimedia_category' ) || is_tax( 'risen_multimedia_speaker' ) || is_tax( 'risen_multimedia_tag' ) || is_post_type_archive( 'risen_multimedia' ) ) { // Prepend page (and parents) that use multimedia template $multimedia_page_id = risen_get_page_id_by_template( 'tpl-multimedia.php' ); if ( $multimedia_page_id ) { $page_breadcrumbs = risen_page_breadcrumbs( $multimedia_page_id ); $breadcrumbs = array_merge( $breadcrumbs, $page_breadcrumbs ); } // Multimedia Item if ( is_singular() ) { // Prepend categories if any $taxonomy = 'risen_multimedia_category'; $terms = get_the_terms( $post->ID, $taxonomy ); $term = is_array( $terms ) ? current( $terms ) : $terms; // use first cat in list if ( ! empty( $term ) ) { $category_breadcrumbs = risen_taxonomy_term_breadcrumbs( $term, $taxonomy ); $breadcrumbs = array_merge( $breadcrumbs, $category_breadcrumbs ); } // Current item //$breadcrumbs[] = array( get_the_title() ); $breadcrumbs[] = array( sprintf( _x( 'View %s', 'multimedia breadcrumb', 'risen'), risen_option( 'multimedia_word_singular' ) ), get_permalink() ); // post titles are often long, so use short generic term } // Multimedia Category or Speaker // Both are hierarchical taxonomies so work the same else if ( is_tax( 'risen_multimedia_category' ) || is_tax( 'risen_multimedia_speaker' ) ) { // Get taxonomy and parents if any $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $breadcrumbs = array_merge( $breadcrumbs, risen_taxonomy_term_breadcrumbs( $term, get_query_var( 'taxonomy' ) ) ); } // Multimedia Tag else if ( is_tax( 'risen_multimedia_tag' ) ) { $breadcrumbs[] = array( sprintf( _x( 'Tagged %s', 'multimedia breadcrumb', 'risen' ), risen_option( 'multimedia_word_plural' ) ), get_term_link( get_query_var( 'term' ), get_query_var( 'taxonomy' ) ) ); } // Multimedia Date Archive else if ( is_year() || is_month() || is_day() ) { // Append date breadcrumbs $base_url = get_post_type_archive_link( get_query_var( 'post_type' ) ); $breadcrumbs = array_merge( $breadcrumbs, risen_date_breadcrumbs( $base_url ) ); } } // Gallery (post, category) else if ( is_singular( 'risen_gallery' ) || is_tax( 'risen_gallery_category' ) ) { // Prepend main gallery page (and parents) chosen in Theme Options $gallery_page_id = risen_option( 'gallery_page_id' ); if ( $gallery_page_id ) { $page_breadcrumbs = risen_page_breadcrumbs( $gallery_page_id ); $breadcrumbs = array_merge( $breadcrumbs, $page_breadcrumbs ); } // Gallery Item if ( is_singular() ) { // Prepend categories if any $taxonomy = 'risen_gallery_category'; $terms = get_the_terms( $post->ID, $taxonomy ); $term = is_array( $terms ) ? current( $terms ) : $terms; // use first cat in list if ( ! empty( $term ) ) { $category_breadcrumbs = risen_taxonomy_term_breadcrumbs( $term, $taxonomy ); $breadcrumbs = array_merge( $breadcrumbs, $category_breadcrumbs ); } // Current item //$breadcrumbs[] = array( get_the_title() ); $gallery_item_type = get_post_meta( $post->ID, '_risen_gallery_type', true ); $gallery_item_type = 'video' == $gallery_item_type ? _x( 'Video', 'gallery item', 'risen' ) : _x( 'Image', 'gallery item', 'risen' ); $breadcrumbs[] = array( sprintf( _x( 'View %s', 'gallery breadcrumb', 'risen' ), $gallery_item_type ), // post titles are often long, so use short generic term get_permalink() ); } // Gallery Category else if ( is_tax( 'risen_gallery_category' ) ) { // Get taxonomy and parents if any $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $breadcrumbs = array_merge( $breadcrumbs, risen_taxonomy_term_breadcrumbs( $term, get_query_var( 'taxonomy' ) ) ); } } // Events else if ( is_singular( 'risen_event' ) ) { // Prepend page (and parents) that use multimedia template $template = risen_event_parent_page_template( $post ); // Use Upcoming or Past template? $events_page_id = risen_get_page_id_by_template( $template ); if ( $events_page_id ) { $page_breadcrumbs = risen_page_breadcrumbs( $events_page_id ); $breadcrumbs = array_merge( $breadcrumbs, $page_breadcrumbs ); } // Single event $breadcrumbs[] = array( _x( 'View Event', 'breadcrumb', 'risen' ), get_permalink() ); } // The Events Calendar Pro if( tribe_is_month() && !is_tax() ) { // The Main Calendar Page } elseif( tribe_is_month() && is_tax() ) { // Calendar Category Pages } elseif( tribe_is_event() && !tribe_is_day() && !is_single() ) { // The Main Events List } elseif( tribe_is_event() && is_single() ) { // Single Events } elseif( tribe_is_day() ) { // Single Event Days } elseif( tribe_is_venue() ) { // Single Venues } else { } // Blog (post, category, tag, search, date archives, author archive) else if ( is_singular( 'post' ) || is_category() || is_tag() || is_search() || is_year() || is_month() || is_day() || is_author() || is_post_type_archive( 'post' ) ) { // Prepend page (and parents) that use blog template $blog_page_id = risen_get_page_id_by_template( 'tpl-blog.php' ); if ( $blog_page_id ) { $page_breadcrumbs = risen_page_breadcrumbs( $blog_page_id ); $breadcrumbs = array_merge( $breadcrumbs, $page_breadcrumbs ); } // Blog Post if ( is_single() ) { // Prepend categories if any $categories = get_the_category(); if ( isset( $categories[0] ) ) { // use first cat in list $category_breadcrumbs = risen_taxonomy_term_breadcrumbs( $categories[0], 'category' ); $breadcrumbs = array_merge( $breadcrumbs, $category_breadcrumbs ); } // Current item //$breadcrumbs[] = array( get_the_title() ); $breadcrumbs[] = array( _x( 'View Post', 'breadcrumb', 'risen' ), // post titles are often long, so use short generic term get_permalink() ); } // Blog Category else if ( is_category() ) { // Get category and parents if any $breadcrumbs = array_merge( $breadcrumbs, risen_taxonomy_term_breadcrumbs( get_query_var( 'cat' ), 'category' ) ); } // Blog Tag else if ( is_tag() ) { $breadcrumbs[] = array( _x( 'Tagged Posts', 'breadcrumb', 'risen' ), get_tag_link( get_query_var( 'tag_id' ) ) ); } // Blog Search else if ( is_search() ) { $breadcrumbs[] = array( _x( 'Search Results', 'breadcrumb', 'risen' ), get_search_link() ); } // Blog Date Archive else if ( is_year() || is_month() || is_day() ) { // Append date breadcrumbs $breadcrumbs = array_merge( $breadcrumbs, risen_date_breadcrumbs() ); } // Blog Author else if ( is_author() ) { $breadcrumbs[] = array( _x( 'Author Archive', 'breadcrumb', 'risen' ), get_author_posts_url( get_query_var( 'author' ) ) ); } } // File not found page else if ( is_404() ) { $breadcrumbs[] = array( __( 'Not Found', 'risen' ), risen_current_url() ); } // Output breadcrumbs if ( ! empty( $breadcrumbs ) ) { // Append Home to front $breadcrumbs = array_merge( array( array( _x( 'Home', 'breadcrumbs', 'risen' ) , home_url() ) ), $breadcrumbs ); // Output $i = 0; $count = count( $breadcrumbs ); echo '