I agree, joshua4. This is how I ended up solving my problem. It’s inelegant, but it works.
If you, like me, want to limit get_categories to a depth of one, you can do this:
<?php global $ancestor; // Declare global ancestor variable ?>
<?php foreach ($categories as $cat) {
if ($cat->cat_ID != 1) { // If category is not uncategorized ...
if (cat_is_ancestor_of($ancestor, intval($cat->cat_ID)) == false) { // .. and if the previous category in the loop wasn't the ancestor of this one ... ?>
<h2><a href="<?php echo get_category_link($cat->cat_ID); ?>"><?php echo ($cat->cat_name); ?></a></h2>
<?php echo ( category_description($cat->cat_ID) ); ?>
<?php
$ancestor = intval($cat->cat_ID); }; // make this category the new ancestor
};
};
?>
If you want to limit depth to two (like displayname does above), you could declare a global $grandparent variable, then at the end of the loop, make the former $ancestor the new $grandparent and the current category the new $ancestor. Then just add another $greatgrandparent if you want a depth of three levels, and so on and so on.
This is a mighty hacky way of just getting depth for get_categories. I think I’ll submit a ticket for that.