While I do not know of a method already implementing this, a simple approach could be to count the amount of (grand)parents like so:
function get_level($id=NULL, $taxonomy='') {
if ( ! $id) {
$id = get_queried_object_id();
}
$term = get_term($id, $taxonomy, OBJECT);
if ($term === NULL)
return 0;
if ($term->parent == 0)
return 1;
return get_level($term->parent, $taxonomy) + 1;
}
Which will return 1 for each term without a parent, 2 for “first level”, etc.
You can use this directly in get_template_part()
. In the example $hierarchical_taxonomies
is an array of taxonomies you want to use these special templates for.
$hierarchical_taxonomies = array('post_tag', 'my_tax');
if (in_array(get_query_var('term'), $hierarchical_taxonomies)) {
get_template_part('taxonomy/level', get_level(NULL, get_query_var('term')));
}
This will try to load taxonomy/level-1.php, taxonomy/level-2.php, .. Make sure these files exist!