Add new items to the top main menu in magento

One of the first things we normally need to modify in a Magento template is the top menu to add extra items or change the way that it is display.

There are several ways to add extra menu items lest see some of them.

 

The magento dirty way
Well they have to say something and they do specialy after magento go.

http://www.magentocommerce.com/knowledge-base/entry/adding-page-links-in-the-navigation-bar

You can have a look to the link but basicaly they fake subcategories and asign links over redirects. I don’t like this because categories are related with products not with cms pages or external links and it is confusing.

Changing your template 
This is the easyest not that bad way.  You go to your templates folder and search for the topmenu.phtml template responsable to show the menu:

appdesignfrontenddefaultyourtemplatetemplatepagehtmltopmenu.phtml

then you can add the links manualy before the </ul> html tag:

<li><a href="<?php echo $this->getUrl('aboutperon') ?>"><?php echo $this->__('About Peron') ?></a></li>

The problem with this way is that will be a bit hacky only for this template and you will loose the active functionality of the css.  You can recreate the active item doing some extra php but still not very nice.

Add a module with an observer 
The observer aproches solve many things in Magento and it is super powerfull when you need to execute some pice of code in specific events.

There are some pages with similar codes on the web but I like MageGyver becouse he has an xml file at the template level with the links insted of build the links at the module level.  Also it is a working sample very easy to implement.

There is a module all ready made in github by MageGyver: https://github.com/MageGyver/Topmenu

See also the blogpost on www.magegyver.de:

http://www.magegyver.de/individual-menu-items-in-the-main-menu/

Tags
About the author
Eduardo Silva was born in Buenos Aires, Argentina, and has being living in London for the past 15 years. With a background in psychology he is a IT developer and the co-founder of open-ecommerce.org, a digital content social enterprise. His passion is digital story-telling and has created short films and documentaries to help people promote there ideas.