Not sure the title says it all...
On the post page (single.php), I'd like to display the lowest child category of the post.
Example :
Animals / Mammals / Cetacae / Dolphins
If a post is in the Dolphins category, I'd like to display "dolphins" on it (like on the top of the page, or such)
I know how to get the categories, I know how to get the top parent category, what I need now is to get the lowest child category.
I figured I'd do it that way :
$category = get_the_category();
$number = count ($category);
echo $category[$number-1]->name;
By getting an array of all categories assigned to my post, and by counting the number of them and substracting 1 to get the last one since the first array slot is 0.
It's working so far, but I'd like to be sure it's correct and will not output crazy results later... Like if a post is assigned to 2 subcategories :
Animals / Mammals / Cetacae / Dolphins
Animals / Mammals / Cetacae / Killer-whales
Which one would it show ? Is it possible to show both ?
Thanks !