Reputation: 124
I'm working on a website where my clients want me to display the parent category of current category. I know how to display the category of current product.
Mage::registry('current_category')->getName();
But I'm struggling to get the parent category of that category. Please help me regarding this. I'm a budding developer.
Upvotes: 0
Views: 2075
Reputation: 641
You can simply use this short code to get the parent category:
$parentId = Mage::registry('current_category')->getParentId();
$parent = Mage::getModel('catalog/category')->load($parentId);
exit($parent->getName());
Upvotes: 0
Reputation: 4331
To get Parent Category Id you must know the current category Id, for that you need to write
<?php
$_cat = new Mage_Catalog_Block_Navigation();
$curent_cat = $_cat->getCurrentCategory();
$curent_cat_id = $curent_cat->getId();?>
Now you can get Parent Category Id. write the code given below to get the Id
<?php $parentId=Mage::getModel('catalog/category')->load($curent_cat_id)->getParentId();
echo $parentId; // $parentId will print your current category's parent Id
?>
Upvotes: 1