WordPress Version: 4.3
/**
* Retrieve path of category template in current or parent template.
*
* Works by first retrieving the current slug, for example 'category-default.php',
* and then trying category ID, for example 'category-1.php', and will finally fall
* back to category.php template, if those files don't exist.
*
* The template path is filterable via the dynamic {@see '$type_template'} hook,
* e.g. 'category_template'.
*
* @since 1.5.0
*
* @see get_query_template()
*
* @return string Full path to category template file.
*/
function get_category_template()
{
$category = get_queried_object();
$templates = array();
if (!empty($category->slug)) {
$templates[] = "category-{$category->slug}.php";
$templates[] = "category-{$category->term_id}.php";
}
$templates[] = 'category.php';
return get_query_template('category', $templates);
}