Created
June 13, 2013 11:54
-
-
Save sambody/5773117 to your computer and use it in GitHub Desktop.
WP: Templates for specific category archive pages. Just use category-catSlug.php or *category-catID.php*. Or for more customization, use the code below. (not for Hybrid theme)
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
// Just use category-catSlug.php or *category-catID.php*, no code necessary. | |
// Or for more customization, use the code below. | |
// add to functions.php: | |
/* Template for certain categories (archive pages, not single) */ | |
add_filter( 'category_template', 'my_category_template' ); | |
// easy to apply to other templates as well ? | |
function my_category_template( $template ) { | |
if( is_category( 1 ) ) // 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