How do I make subcategories inherit the template of the parent category?

I have a parent category (let’s call it FILMS category-films.php) and it has it’s own template to display all child posts with custom HTML.

Within this category are a number of subcategories (e.g. HORROR, SCI-FI, COMEDY etc.).

I’d like the subcategory pages to display posts using the category-films.php template without having to duplicate it and create a new php file for every subcategory.

I’ve found a few threads online that have functions to achieve this (http://stackoverflow.com/questions/3114934/make-wordpress-subcategories-use-category-template/3117202#3117202) but I’m not sure how this might need to be modified for Roots.

That code won’t work because they are doing things badly. Adapt it to use the template_include filter as per the article and you should be fine.

1 Like

Thanks Nick - working now. Much appreciated!

In case anyone is feeling lazy this is the final function (‘5’ being my parent category):

add_filter( 'template_include', 'film_subcats_use_film_template' );

function film_subcats_use_film_template( $original_template ) {

   $catid = get_query_var('cat');

  if ( cat_is_ancestor_of( 5, $catid) ) {
    return TEMPLATEPATH . '/category-films.php';
  } else {
    return $original_template;
  }

}