jlramirez, your method adds an extra database quary, but none is needed. There's a faster and easier way, that has been documented in this thread too: here's my version of it (catalog/includes/coolmenu.php):
$categories = tep_get_categories('');
$height = -21;
$depth=0;
$blank_length;
$depth_size;
$depth_parentid;
for($i=0; $i<count($categories); $i++) { // don't insert 1st entry ("please choose ...")
$blank_length = blank_length($categories[$i]['text']);
if($blank_length == $depth) {
$categories[$i]['depth'] = $depth;
$depth_size[$depth]++;
} else if ($blank_length > $depth) {
$depth++;
$categories[$i]['depth'] = $depth;
$depth_size[$depth]++;
} else if ($blank_length < $depth) {
for ($j=$depth; $j>$blank_length; $j--) {
$depth_size[$j] = 0;
$depth--;
}
$categories[$i]['depth'] = $depth;
$depth_size[$depth]++;
}
$depth_parentid[$categories[$i]['depth']] = $categories[$i]['id'];
// remove blanks
$categories[$i]['text'] = substr($categories[$i]['text'], 12*$blank_length);
if ($depth == 0) {
$height += 17; // use oCMenu.level[0].height + 1 !!
}
print_menu_line($categories[$i], $depth_size,$depth_parentid, $depth);
}
Comments:
$height = -21; //I don't know why -21, but i found out it works for me. maybe someone can explain?
if ($depth == 0) //then it's a top level category, no db query needed
$height += 17; // use what you took as oCMenu.level[0].height + 1 !! plus one because of the border
For me, the above code works perfectly for all numbers of categories and all sizes of oCMenu.level[0].height .
Nils
Exactly!!, when i wrote my hack i was in such a hurry that i didn't even notice what the for() was (or at least i don't remember giving it a look). And it is exactly what i was looking for, a way to tell how many top-level categories there are, and of course if($depth == 0).... duh!!.
Well i'm very sorry for that sorry piece of code. I'll have to link yours when someone else asks the same question.
Is there a FAQ/Tips and Tricks for this one, its asked quite frequently.
Cheers!!!