How to determine the nesting level of a category Wordpress?

The situation is this:
there are categories
Directory
- Level 2
-- Level 3
--- Entry
How to write a condition for category.php,
that would output different code for each level of categories?
July 9th 19 at 13:37
1 answer
July 9th 19 at 13:39
$current_cat_id = get_query_var('cat');
$child = get_category($current_cat_id);
$level2 = $child->parent;
$child2 = get_category($level2);
$level3 = $child2->parent;

if(is_category(6)){
 include "catalog.php";
} else if ($level2 == 6){
 include "catalog_level2.php";
} else if ($level3 == 6){
 include "catalog_level3.php";
}

Find more questions by tags WordPress