21 Apr 2010
WordPress Hacks : Get the depth of a category or Category depth
WordPress doesn’t have a function to get the depth of a category. Here is a function to get the depth of a category, I wrote a while back with the help of Jens Törnell code:
function get_category_depth($id = '', $depth = '', $i = 0)
{
global $wpdb;
global $term_taxonomy;
if($depth == '')
{
if(is_category())
{
if($id == '')
{
$id = $term_taxonomy->term_id;
}
$depth = $wpdb->get_var("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = '".$id."'");
return get_category_depth($id, $depth, $i);
}
}
elseif($depth == "0")
{
return $i;
}
else
{
$depth = $wpdb->get_var("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = '".$depth."'");
$i++;
return get_category_depth($id, $depth, $i);
}
}
[...] This post was mentioned on Twitter by Safiweb Interactive. Safiweb Interactive said: Get the depth of a category or category depth in wordpress : http://bit.ly/aULD29 #wordpress [...]