Skip to content

Instantly share code, notes, and snippets.

@isotrope
Last active August 29, 2015 14:13
Show Gist options
  • Save isotrope/a515f199fccc9ea47b64 to your computer and use it in GitHub Desktop.
Save isotrope/a515f199fccc9ea47b64 to your computer and use it in GitHub Desktop.
If theme has view, use it. Else, use the one included with the plugin.
public function event_template_redirect() {
global $post, $wp;
$plugindir = dirname( __FILE__ );
$return_template = '';
if ( is_tax( 'iso_season' ) ) {
$templatefilename = 'archive-events.php';
if ( file_exists( TEMPLATEPATH . '/' . $templatefilename ) ) {
$return_template = TEMPLATEPATH . '/' . $templatefilename;
} else {
$return_template = $plugindir . '/templates/' . $templatefilename;
}
} else if ( get_post_type() == 'iso_event' && is_single() ) {
$templatefilename = 'single-event.php';
if ( file_exists( TEMPLATEPATH . '/' . $templatefilename ) ) {
$return_template = TEMPLATEPATH . '/' . $templatefilename;
} else {
$return_template = $plugindir . '/templates/' . $templatefilename;
}
}
if ( $return_template != '' ) {
$this->do_theme_redirect( $return_template );
}
}
public function do_theme_redirect( $url ) {
global $wp, $post, $wp_query;
if ( have_posts() ) {
include( $url );
die();
} else {
$wp_query->is_404 = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment