WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/category template

Intro

This hook can be used to filter the default WordPress Template Hierarchy and load a custom category template.

Examples

This example loads a custom category template for categories 62,65 and 59.

add_filter( 'category_template', 'filter_category_template', 99 );

function filter_category_template( $template ) {

	 if ( is_category(array( 64,65,59 )  )  ) {
		$new_template = locate_template( array( 'category-template.php' ) );
		if ( '' != $new_template ) {
			return $new_template;
		}
	}

	return $template;
}

Here's another way to write the code

add_filter( 'category_template', 'custom_category_template' );
function custom_category_template( $template ) {
    
      if ( is_category(array( 64,65,59 )  )  ) {
    
    $template = locate_template( 'custom.php' ); 
    }
    return $template;
}

Source Files

This filter is applied in wp-includes/template-loader.php

Related

See also index of Function Reference and index of Template Tags.