In the category page of the Magento directory, you want to get the parent and sub-categories in the left navigation , using the following methods:
Open app/your_package/your_themes/template/catalog/navigation/left.phtml
Show category name of the parent category
| 12345678910 |
$currentCat = mage::registry ( Code class= "PHP string" > ' current_category ' //If it is the root directory, the current directory is displayed if ( $currentCat -> Getparentid () = = Mage::app ()->getstore ()->getrootcategoryid ()) //Show current directory name echo $this - >getcurrentcategory ()->getname (); else { //Display the parent category name of the current directory $this ->getcurrentcategory () Getparentcategory ()->getname (); } |
Show classification names for subcategories
The sub-classifications shown are based on the current parent classification
| 1234567891011121314151617181920212223 |
$currentCat = Mage::registry(‘current_category‘);if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() ){ // 当前分类是顶级分类 $loadCategory = $currentCat;}else{ // 当前分类是顶级分类的的一个子分类,载入当前分类的父分类 $loadCategory = Mage::getModel(‘catalog/category‘)->load($currentCat->getParentId());}$subCategories = explode(‘,‘, $loadCategory->getChildren());foreach ( $subCategories as $subCategoryId ){ $cat = Mage::getModel(‘catalog/category‘)->load($subCategoryId); if($cat->getIsActive()) { echo ‘<a href="‘.$cat->getURL().‘">‘.$cat->getName().‘</a>‘; }} |
Original articles, reproduced please specify: reprinted from the Magento Architect's Notes | Magento Displays the category name of the parent and subcategory of the current directory
This article link address: http://www.magentonotes.com/display-parent-category-and-subcategories-of-current-parent-in-magento.html
Posts related toMagento Displays the category name of the parent and subcategory of the current directory
Magento Architect's Notes-----Magento displays the category names of the parent and subcategory of the current directory