Created
May 20, 2014 10:32
-
-
Save ivandoric/d509744114401514280b to your computer and use it in GitHub Desktop.
wordpress: Check at what depth is the current category
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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