Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Created August 28, 2011 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zanematthew/1176164 to your computer and use it in GitHub Desktop.
Save zanematthew/1176164 to your computer and use it in GitHub Desktop.
Redirecting a template in WordPress using a switch. This is used inside of a plugin when you want to allow default template for a Custom Post Type your template is generating.
case ( is_tax( $my_taxonomies ) ):
global $wp_query;
if ( in_array( $wp_query->query_vars['taxonomy'], $my_taxonomies ) ) {
foreach ( $my_taxonomies as $taxonomy ) {
load_template( MY_PLUGIN_DIR . 'theme/archive-' . $k['type'] . '.php' );
// load_template( MY_PLUGIN_DIR . 'theme/taxonomy-' . $my_taxonomies. '.php' );
}
}
exit;
break;
case ( is_single() ):
// If your not my post type GTFO
foreach ( $this->post_type as $my_post_type )
if ( get_post_type() != $my_post_type['type'] ) return;
// first checkout our plugin themes folder
foreach ( $this->post_type as $my_post_type )
if ( file_exists( STYLESHEETPATH . '/single-' . $my_post_type['type'] . '.php' ) ) return;
foreach ( $this->post_type as $my_post_type )
load_template( MY_PLUGIN_DIR . '/theme/single-' . $my_post_type['type'] . '.php' );
exit;
break;
case ( is_post_type_archive( $k['type'] ) ):
if ( file_exists( STYLESHEETPATH . '/archive-' . $k['type'] . '.php' ) ) return;
load_template( $this->plugin_dir . '/theme/archive-' . $k['type'] . '.php' );
exit;
break;
default:
return;
} // End 'switch'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment