1// Use a parent category slug if it exists
2function child_force_category_template($template) {
3 $cat = get_query_var('cat');
4 $category = get_category($cat);
5
6 if ( file_exists(TEMPLATEPATH . '/category-' . $category->cat_ID . '.php') ) {
7 $cat_template = TEMPLATEPATH . '/category-' . $category ->cat_ID . '.php';
8 } elseif ( file_exists(TEMPLATEPATH . '/category-' . $category->slug . '.php') ) {
9 $cat_template = TEMPLATEPATH . '/category-' . $category ->slug . '.php';
10 } elseif ( file_exists(TEMPLATEPATH . '/category-' . $category->category_parent . '.php') ) {
11 $cat_template = TEMPLATEPATH . '/category-' . $category->category_parent . '.php';
12 } else {
13 // Get Parent Slug
14 $cat_parent = get_category($category->category_parent);
15
16 if ( file_exists(TEMPLATEPATH . '/category-' . $cat_parent->slug . '.php') ) {
17 $cat_template = TEMPLATEPATH . '/category-' . $cat_parent->slug . '.php';
18 } else {
19 $cat_template = $template;
20 }
21
22 }
23
24 return $cat_template;
25}
26add_action('category_template', 'child_force_category_template');
27