Magento – Show Only Subcategories of Specific Category in Top Menu

menunavigation

These are my categories :

Root category
---> Shoes
---- ---> Red    shoes
---- ---> Green  shoes
---- ---> Yellow shoes
---> Shirts
---- ---> Black shirts
---- ---> White shirts
---- ---> Blue  shirts

and my top menu would be like:

-Shoes -Shirts

But I only want to show my shoes in the top menu, Like this :

-Red shoes -Green shoes -Yellow shoes

How can I do that?

Best Answer

The categories are added in the top menu using this method Mage_Catalog_Model_Observer::addCatalogToTopmenuItems.
buy default the method looks like this:

public function addCatalogToTopmenuItems(Varien_Event_Observer $observer)
{
    $this->_addCategoriesToMenu(Mage::helper('catalog/category')->getStoreCategories(), $observer->getMenu());
}

This means that it adds to the top menu the result of Mage::helper('catalog/category')->getStoreCategories() recursively.
All you need to do is to rewrite this method and make it show only the child categories you need.

Something like this. Let's say that your shoes category id is 5.

public function addCatalogToTopmenuItems(Varien_Event_Observer $observer)
{
    $parent = 5;
    $recursionLevel  = max(0, (int) Mage::app()->getStore()->getConfig('catalog/navigation/max_depth') - 1) //subtract 1 from the set recursion level because we skip a level;
    $categories= Mage::getModel('catalog/category')->getCategories($parent, $recursionLevel, false, false, true);
    $this->_addCategoriesToMenu($categories, $observer->getMenu());
}

I haven't tested it, but I think the idea is there.