I'm looking for a solution to dynamically create different templates for each category level.
Category
--Category
---Category
----Category
I thought of something to get the taxonomy current level ID, to use a function like below, but I did not find a solution.
I have not found anything that returns me level or a unique ID for each level in a taxonomy
$term = get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') );
echo $term->cat_level_id;
switch ($current_level_id) {
case 'level_1':
get_template_part( 'taxonomy-content-level_1',);
break;
case 'level_2':
get_template_part( 'taxonomy-content-level_2',);
break;
case 'level_3':
get_template_part( 'taxonomy-content-level_3',);
break;
case 'level_4':
get_template_part( 'taxonomy-content-level_4' );
break;
}
I know that wordpress understands taxonomy-custom-slug.php, but it's not something I can use because it's not feasible to create templates since there are many categories / sub.
Thanks in advance for your attention.