Skip to content

Instantly share code, notes, and snippets.

@ivandoric
Created May 20, 2014 10:32
Show Gist options
  • Save ivandoric/d509744114401514280b to your computer and use it in GitHub Desktop.
Save ivandoric/d509744114401514280b to your computer and use it in GitHub Desktop.
wordpress: Check at what depth is the current category
<?php
//TEST AT WHAT DEPTH IS CURRENT CATEGORY
$max_depth_to_test = intval(3); //set this to highest depth you might have
$last_depth = 0;
$cat_to_test = $cat;
$category=get_category($cat_to_test);
for ( $counter = 1; $counter <= $max_depth_to_test; $counter += 1) {
if ($category->category_parent) {
$category=get_category($category->category_parent);
$last_depth = $counter;
}
}
$last_depth +=1;
//echo '<p>Category ' . $cat_to_test . ' it is at depth ' . $last_depth .'</p>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment