Skip to content

Instantly share code, notes, and snippets.

@sambody
Created June 13, 2013 11:54
Show Gist options
  • Save sambody/5773117 to your computer and use it in GitHub Desktop.
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)
// 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