Magento Architect's Notes-----Magento displays the category names of the parent and subcategory of the current directory

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.