Tribe__Events__Templates::templateChooser( string $template )
Pick the correct template to include
Contents
Parameters
- $template
-
(string) (Required) Path to template
Return
(string) Path to template
Source
File: src/Tribe/Templates.php
public static function templateChooser( $template ) {
$events = Tribe__Events__Main::instance();
do_action( 'tribe_tec_template_chooser', $template );
// no non-events need apply
if ( ! tribe_is_event_query() ) {
return $template;
}
// if it's a single 404 event
if ( is_single() && is_404() ) {
return get_404_template();
}
if (
! is_single()
&& ! tribe_events_is_view_enabled( $events->displaying )
// we want the day view to display if visited (this allows it to be largely disabled while
// still allowing month overflow links to work correctly)
&& 'day' != $events->displaying
) {
return get_404_template();
}
// add the theme slug to the body class
add_filter( 'body_class', array( __CLASS__, 'theme_body_class' ) );
// add the template name to the body class
add_filter( 'body_class', array( __CLASS__, 'template_body_class' ) );
// user has selected a page/custom page template
if ( tribe_get_option( 'tribeEventsTemplate', 'default' ) != '' ) {
if ( ! is_single() || ! post_password_required() ) {
add_action( 'loop_start', array( __CLASS__, 'setup_ecp_template' ) );
}
$template = tribe_get_option( 'tribeEventsTemplate', 'default' ) !== 'default'
? locate_template( tribe_get_option( 'tribeEventsTemplate', 'default' ) )
: get_page_template();
if ( $template == '' ) {
$template = get_index_template();
}
// remove singular body class if sidebar-page.php
if ( $template == get_stylesheet_directory() . '/sidebar-page.php' ) {
add_filter( 'body_class', array( __CLASS__, 'remove_singular_body_class' ) );
} else {
add_filter( 'body_class', array( __CLASS__, 'add_singular_body_class' ) );
}
} else {
$template = self::getTemplateHierarchy( 'default-template' );
}
// if this is an oembed, override the wrapping template and use the embed template
if ( Tribe__Templates::is_embed() ) {
$template = self::getTemplateHierarchy( 'embed' );
}
self::$template = $template;
return $template;
}