Magento Themes and Magento Extensions

How to display Parent Category of a subcategory


In Magento : To display the parent category of the subcategory you are located in you will have to use the current code. We used this into a file called list_parent.phtml located on our sidebar on this location:
/app/design/frontend/default/YOUR THEME/template/catalog/navigation/list_parent.phtml

<div> <strong><span><?php echo $this->__('Browse By') ?></span></strong> </div>
<dl id="narrow-by-list2">
  <dt><?php echo $this->__('Category') ?></dt>
                $currentCat = Mage::registry('current_category');
                //if Rootcategory display current category only
                //this gets around the problem of displaying DEFAULT CATEGORY
                if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
                    //Display current category
                    echo $this->getCurrentCategory()->getName() ;
                        // Display ParentCategory of Current Category
                        echo $this->getCurrentCategory()->getParentCategory()->getName() ;

With this code if you are a in a subcategory of the Default Category, then the code checks this and it displays you current category.

As I’ve said earlier we used this code on the sidebar, on a category page (product listing page). To call this file on the category page you have to add the below code into your catalog.xml (under /app/design/frontend/default/YOUR THEME/layout/catalog.xml):

<reference name="left">
<block type="catalog/navigation" name="catalog.list_parent" after="currency"

We added this call for the Non-Anchor Category page, but you can call it wherever you want

Comments are closed.