Reputation: 3528
My categories and subcategories hierarchy to a product listing page :
Now, what i'm trying to get is while i'm in product listing page i want to get all the parent categories and subcategories with respective links.
What i tried is :
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
But this doesn't render in product listing page. So how can i get all the active categories and subcategories in product listing page their links that will take me to the respective category/subcategory page.
Upvotes: 0
Views: 1327
Reputation: 9045
<?php $currentCategoryId = $this->getLayer()->getCurrentCategory()->getId();
$curentCategory = Mage::getModel('catalog/category')->load($currentCategoryId);
$path = $curentCategory->getPath();
// $path will return category IDs like "1/5/16/30/45" : Here, 1 is the main root category & 2 is the Default magento root category. After these, you will get the category Ids by hierarchy .
/*
* Output "1/5/16/30/45" will have following hierarchy
*1-
* 2-
* 16-
* 30-
* 45
*/
// later you can explode by slash(/) and go ahead with your further display logics
?>
Upvotes: 1