Magento – Magento : Show 3 different top menus

categorymenu

I tried (without success) to show 3 different menus: – Menu1: for the home page having the subcategories : Home SubMenu1, Home SubMenu2 and Home SubMenu3 – Menu2: for the online Shop having Cat1 SubMenu1, Cat1 SubMenu2 and Cat1 SubMenu3 visible – And Menu3; visible only in the CMS pages and having the 3 sub-elements visible : Cat2 SubMenu1, Cat2 SubMenu2 and Cat2 SubMenu3

The structure of my categories is like this:

Default Category
    |– Home Menu    (Is Active : No)
    |   |– Home SubMenu1    (Is Active : Yes)
    |   |– Home SubMenu2    (Is Active : Yes)
    |   |– Home SubMenu3    (Is Active : Yes)
    |
    |– Cat1 (Is Active : No)
    |   |– Cat1 SubMenu1    (Is Active : Yes)
    |   |– Cat1 SubMenu2    (Is Active : Yes)
    |   |– Cat1 SubMenu3    (Is Active : Yes)
    |
    |– Cat2 (Is Active : No)
    |   |– Cat2 SubMenu1    (Is Active : Yes)
    |   |– Cat2 SubMenu2    (Is Active : Yes)
    |   |– Cat2 SubMenu3    (Is Active : Yes)

Any help?

Many thanks in advance!

Best Answer

It's not possible with the default top navigation offered in Magento CE.

You can however write a custom extension that returns a collection of category links depending on the type of page.

class [Namespace]_[Module]_Block_Menu extends Mage_Core_Block_Template
{
   public function getMenu()
   {
      if (Mage::getSingleton('cms/page')->getIdentifier() == 'home')
      {
          $parent_id = [home cat id];
      }
      elseif (Mage::app()->getRequest()->getModuleName() == 'catalog')
      {
          $parent_id = [catalog cat id];
      }
      elseif (Mage::app()->getRequest()->getModuleName() == 'cms')
      {
          $parent_id = [cms cat id];
      }

      $main = Mage::getModel('catalog/category')->load($parent_id);
      $menu = array(
         'name' => $main->getName(),
         'url' => $main->getUrl(),
         'children' => array(),
      );

      $children = Mage::getModel('catalog/category')->getCollection()
         ->addAttributeToFilter('parent_id', $main->getId());
      foreach ($children as $item)
      {
         $menu['children'][] = array('name'=>$item->getName(), 'url'=>$item->getUrl());
      }

      return $menu;
   }
}

Now in a custom PHTML file you can use the menu array to run through all the items and build a menu.

To replace the old menu with your new one add the following to your local.xml

<reference name="header">
   <remove name="top.menu"/>
   <block type="[module]/menu" name="custom_menu" as="topMenu" template="your/custom/template.phtml"/>
</reference>

This is however a very inflexible solutions as when you change a category it might break the menu. I'm not big on promoting paid extensions but you might want to give Menubuilder a try as it provides for a lot of flexibility.

Related Topic