I am implementing the Magento catalog product view page, and I need the name of subcategory the product is added to.
The code to display the category is like: $_product->category->name
but I am unable to get the sub category name.
Well I got the sub categories the following way:
<?php
if (Mage::registry('current_product')) {
if ($_product) {
$categoryIds = $_product->getCategoryIds();
$cat_id = $categoryIds[0]; ----> pass the level of sub catgeory to the array index
$category = Mage::getModel('catalog/category')->load($cat_id);
$cat_name = $category->getName();
}
}
?>