Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

I have a custom taxonomy called product-categories. Currently all categories use the master template (taxonomy-product-categories.php).

The category tree is roughly as follows.

Products 
- Cheese
-- Types of Cheese
--- Cheddar
--- Brie
--- Cheshire
-- Types of Milk
--- Cows Cheese
--- Goats Cheese
- Cakes
- Category

I want to set it so that all categories, including sub_categories in the cheese section of the tree use a cheese template (taxonomy-product-categories-cheese.php). With other templates for the other areas.

I've found a two year old post which appears to be the solution but does not appear to do anything.

Make Custom Taxonomy Category Use Parent TemplateMake Custom Taxonomy Category Use Parent Template

I've added the following to my functions.php

add_filter('template_include', 'cheese_term_template');

function cheese_term_template( $template ) {
  if ( is_tax('classifications') ) {
    // $parent = get_term_by('slug', 'cheese', 'classifications');
    $parent = 13;
    if ( term_is_ancestor_of( $parent, get_queried_object(), 'classifications' ) )
       return get_template_directory() . '/taxonomy-product-categories-cheese.php';
  }
  return $template;
}

I though that it was looking at the top level category instead but when I did some tests it didn't work with that either. I wonder if it was because the taxonomy name has a hyphen in it.

I'd appreciate any help... Thanks

I have a custom taxonomy called product-categories. Currently all categories use the master template (taxonomy-product-categories.php).

The category tree is roughly as follows.

Products 
- Cheese
-- Types of Cheese
--- Cheddar
--- Brie
--- Cheshire
-- Types of Milk
--- Cows Cheese
--- Goats Cheese
- Cakes
- Category

I want to set it so that all categories, including sub_categories in the cheese section of the tree use a cheese template (taxonomy-product-categories-cheese.php). With other templates for the other areas.

I've found a two year old post which appears to be the solution but does not appear to do anything.

Make Custom Taxonomy Category Use Parent Template

I've added the following to my functions.php

add_filter('template_include', 'cheese_term_template');

function cheese_term_template( $template ) {
  if ( is_tax('classifications') ) {
    // $parent = get_term_by('slug', 'cheese', 'classifications');
    $parent = 13;
    if ( term_is_ancestor_of( $parent, get_queried_object(), 'classifications' ) )
       return get_template_directory() . '/taxonomy-product-categories-cheese.php';
  }
  return $template;
}

I though that it was looking at the top level category instead but when I did some tests it didn't work with that either. I wonder if it was because the taxonomy name has a hyphen in it.

I'd appreciate any help... Thanks

I have a custom taxonomy called product-categories. Currently all categories use the master template (taxonomy-product-categories.php).

The category tree is roughly as follows.

Products 
- Cheese
-- Types of Cheese
--- Cheddar
--- Brie
--- Cheshire
-- Types of Milk
--- Cows Cheese
--- Goats Cheese
- Cakes
- Category

I want to set it so that all categories, including sub_categories in the cheese section of the tree use a cheese template (taxonomy-product-categories-cheese.php). With other templates for the other areas.

I've found a two year old post which appears to be the solution but does not appear to do anything.

Make Custom Taxonomy Category Use Parent Template

I've added the following to my functions.php

add_filter('template_include', 'cheese_term_template');

function cheese_term_template( $template ) {
  if ( is_tax('classifications') ) {
    // $parent = get_term_by('slug', 'cheese', 'classifications');
    $parent = 13;
    if ( term_is_ancestor_of( $parent, get_queried_object(), 'classifications' ) )
       return get_template_directory() . '/taxonomy-product-categories-cheese.php';
  }
  return $template;
}

I though that it was looking at the top level category instead but when I did some tests it didn't work with that either. I wonder if it was because the taxonomy name has a hyphen in it.

I'd appreciate any help... Thanks

Source Link
Legin76
  • 117
  • 1
  • 7

Make child taxonomy categories use a set template

I have a custom taxonomy called product-categories. Currently all categories use the master template (taxonomy-product-categories.php).

The category tree is roughly as follows.

Products 
- Cheese
-- Types of Cheese
--- Cheddar
--- Brie
--- Cheshire
-- Types of Milk
--- Cows Cheese
--- Goats Cheese
- Cakes
- Category

I want to set it so that all categories, including sub_categories in the cheese section of the tree use a cheese template (taxonomy-product-categories-cheese.php). With other templates for the other areas.

I've found a two year old post which appears to be the solution but does not appear to do anything.

Make Custom Taxonomy Category Use Parent Template

I've added the following to my functions.php

add_filter('template_include', 'cheese_term_template');

function cheese_term_template( $template ) {
  if ( is_tax('classifications') ) {
    // $parent = get_term_by('slug', 'cheese', 'classifications');
    $parent = 13;
    if ( term_is_ancestor_of( $parent, get_queried_object(), 'classifications' ) )
       return get_template_directory() . '/taxonomy-product-categories-cheese.php';
  }
  return $template;
}

I though that it was looking at the top level category instead but when I did some tests it didn't work with that either. I wonder if it was because the taxonomy name has a hyphen in it.

I'd appreciate any help... Thanks