S
S
Sergei Gurdjiyan2016-05-17 16:44:10
WordPress
Sergei Gurdjiyan, 2016-05-17 16:44:10

How to determine the nesting level of a Wordpress category?

The situation is this:
there are categories
Catalog
- Level 2
- Level 3
- Record
How to write a condition for category.php
to display different code at each category level?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergei Gurdjiyan, 2016-05-18
@mrKorg

$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";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question