天机不可泄漏也

我有书半卷

导航

Magento显示当前目录的父分类和子分类的分类名

显示父分类的分类名

 1 $currentCat = Mage::registry('current_category');
2 //如果是根目录,则显示当前目录
3 if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
4 //显示当前目录名
5 echo $this->getCurrentCategory()->getName() ;
6 else
7 {
8 //显示当前目录的父分类名
9 echo $this->getCurrentCategory()->getParentCategory()->getName() ;
10 }

显示子分类的分类名

显示的子分类是建立在当前的父分类的基础上

 1 $currentCat = Mage::registry('current_category');
2
3 if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
4 {
5 // 当前分类是顶级分类
6 $loadCategory = $currentCat;
7 }
8 else
9 {
10 // 当前分类是顶级分类的的一个子分类,载入当前分类的父分类
11 $loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
12 }
13 $subCategories = explode(',', $loadCategory->getChildren());
14
15 foreach ( $subCategories as $subCategoryId )
16 {
17 $cat = Mage::getModel('catalog/category')->load($subCategoryId);
18
19 if($cat->getIsActive())
20 {
21 echo '<a href="'.$cat->getURL().'">'.$cat->getName().'</a>';
22 }
23 }


posted on 2011-08-30 14:07  天机不可泄漏也  阅读(736)  评论(0编辑  收藏  举报