我的产品列表页面的类别和子类别层次结构:
现在,我想要获得的是,当我在产品详情页面中时,我希望获得具有相应链接的所有父类别和子类别。
我尝试的是:
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
但这不会在产品详情页面中呈现。那么如何才能将产品列表页面中的所有活动类别和子类别链接到相应的类别/子类别页面。
答案 0 :(得分:1)
<?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
?>