How to Display Subcategories in Magento

Blog Banner
There are many tutorials on how to add navigation to your Magento ecommerce website, but not a lot of tutorials on once you add your navigation how to display subcategories.

Step 1:

Open your text editor (Dreamweaver, Notepad++, etc.) and create a new .phtml file.  Copy the following code into your new file:

<?php
   $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-&gt;getURL().'">'.$cat-&gt;getName().'</a>';
        }
    }
?>

Save the file in /app/design/frontend/YOURTEMPLATE/default/template/catalog/navigation/

Step 2:

Open your catalog.xml file located at: /app/design/frontend/YOURTEMPLATE/default/layout/ and copy the following code to the Catalog Category section:

<reference name="right">
 <block template="catalog/navigation/YOURFILE.phtml" before="-" name="catalog.YOURFILE" type="catalog/navigation">
 </block> 
</reference>

Save your catalog.xml file and refresh your cache (screenshot below):

And now you should see your subcategories displayed based off of the Parent navigation.

Need further assistance or help with subcategories, leave your comment or questions below.

 

 

Tags

 
blog rss banner
 

View All

Testimonials

“Unleashed Technologies is a pleasure to work with. We needed an unusual, non-cookie-cutter web site on a very tight schedule, and Unleashed Technologies delivered.

Paul Jakubik
PureDiscovery Corporation

“It was a pleasure working with Michael Spinosa and his team from Unleashed Technologies.

Jordan Sopher
Eyemaginations, Inc.