For example I have a product called
Nike shoes and it has categories
Catalog > Shoes > Men.
What I need is just to get the name of the last category (
Men). At first glance it can be retrieved very easily:
$cat = $_product->getCategoryIds(); $name= Mage::getModel('catalog/category')->load( end($cat) )->getName();
But there is a big problem, function
getCategoryIds() return array of category ID's sorted numerically - so if last category (e.g.
Men) has smaller index then previous one (e.g.
Shoes) - I'll get incorrect result (
Question: how to get list of category ID's sorted in the same way as on "Manage Categories" page? Or just how to get the last category?