Created
June 29, 2012 02:11
-
-
Save reediredale/3015234 to your computer and use it in GitHub Desktop.
Using the same template across multiple category, tag, and author pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
?php | |
// Inspired by a snippet by Justin Tadlock (http://justintadlock.com/) posted here: http://elliotjaystocks.com/blog/tutorial-multiple-singlephp-templates-in-wordpress/#comment-2383 | |
add_filter( 'category_template', 'my_category_template' ); | |
// I believe *_template hooks exist for just about every type of template so it's easy to apply to other templates as well | |
function my_category_template( $template ) { | |
if( is_category( 1 ) ) // We can search for categories by ID | |
$template = locate_template( array( 'template_id_A.php', 'category.php' ) ); | |
elseif( is_category( array( 21, 32 ) ) ) // We can search for multiple categories by ID by passing an array | |
$template = locate_template( array( 'template_id_B.php', 'category.php' ) ); | |
elseif( is_category( 'food' ) ) // We can search for categories by their slug | |
$template = locate_template( array( 'template_slug_A.php', 'category.php' ) ); | |
elseif( is_category( array( 'music', 'movies' ) ) ) // We can search for multiple categories by slug as well | |
$template = locate_template( array( 'template_slug_A.php', 'category.php' ) ); | |
return $template; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment