Magento is arguably the most robust and advanced open-source e-commerce system available in the marketplace today, it is not however without it’s little annoying traits and as you know it’s the little things that lift that matter. One thing that Magento does not easily allow you to do as yet is hide a category in the top navigation but still show it in the sidebar navigation, luckily this tutorial will show you exactly how to acheive this feature by editing your template file for the top category navigation bar.
This particular method will allow you to exclude individual categories by ID number from you top navigation menu in Magento.
Firstly depending on which theme you are using for magento you will want to locate the top.phtml which is the file that requires editing to exclude individual categories. You can find the original copy of this file in /app/design/frontend/base/default/template/catalog/navigation/top.phtml.
Copy the top.phtml file to the theme you are using to style you magento store place it in the /app/design/frontend/default/YOURTHEMENAME/template/catalog/navigation/top.phtml folder. If the folder “navigation” does not exist within the catalog folder in your theme simply create it.
Now open the top.phtml file with an HTML / PHP friendly text editor.
The original contents of the top.phtml file should look like below.
<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<ul id="nav">
<?php echo $_menu ?>
</ul>
</div>
<?php endif ?>
Replace the code above with this code below.
<?php $_menu = ''?>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php $_menu .= $this->drawItem($_category) ?>
<?php endforeach ?>
<?php if ($_menu): ?>
<div class="nav-container">
<ul id="nav">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php if (!in_array($_category->getId(), array(12,34,56))) : ?> <?php echo $this->drawItem($_category) ?>
<?php endif; ?>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
Now to exclude categories from your top navigation menu you can simple enter the category ID number you wish to exclude where the example numbers 12,34,56 are in the code above.
To find out the ID of a category go to your Magento Admin panel and Categories, when you click to edit a category at the top left you will see it’s numerical ID.
This trick can be particular useful for designers when the client wants more categories than the top navigation menu will allow. The excluded categories still show up in the main sidebar navigation menu of course as we have made no edits to that. This may not be the most elegant of solutions i.e. you can only exclude the categories by editing a template file for building custom themes though it can be a life saver.
March 14, 2011 at 1:40 pm
Doesn’t work for Magento 1.4.0.1 I’m afraid
Any ideas?
March 15, 2011 at 1:58 am
Hi Michael we have this code running on an live install of both v1.4.0.1 and v1.5.0.1 of magento so we can confirm that it works on both of these versions.
March 26, 2011 at 7:06 pm
Thanks worked a treat on 1.5!
March 28, 2011 at 11:37 am
Thanks for some independent confirmation that this works for v1.5, much appreciated.
April 10, 2011 at 6:54 am
I found that I had to clear the cache and then it worked.
June 13, 2011 at 1:57 pm
I need to remove or preferably place the product category bar that is at the top of the home page down lower on the home page or off the “home page only” all together leaving it where it is at on all other pages…..
Thoughts?
Can you help?
July 15, 2011 at 6:21 pm
not working in 1.4.1.1 . any idea? thanks
July 19, 2011 at 2:19 pm
It should work in v1.4.1.1 carlagnas? unfortunatley it not working could be caused by many things, too many to narrow down without more detailed information from yourself.
July 18, 2011 at 10:32 am
This was fantastic! Exactly what I needed and so easy to install!!!
July 19, 2011 at 2:20 pm
Thats great news Heidi glad it helped you out
September 6, 2011 at 3:15 am
Not working for me under 1.5.1.0 either. Strange, cleared cache numerous times and reindexed twice.
September 6, 2011 at 5:41 am
It was me, we use supermenu which has its own navigation menu. I just replaced the code inside that and all is good, thanks!
September 9, 2011 at 4:58 pm
Fantastic news PP good to hear the code snippet worked for you in supermenu
September 28, 2011 at 9:03 am
Awesome ………………………….!!!!!!!!!!!
You did a great job …………
September 29, 2011 at 10:53 am
Is there a way to perform this but to sub-categories of TOP categories? in fact what im trying to do is to check if the SUB-category have products inside or not…
October 16, 2011 at 1:03 pm
hi, can you help me, this is exactly what I need but cant get it to work, magento 1.6, I think I have done it right, my updated code is below, it removes all the categories except the Home link, any help would be great!
Cheers
* Top menu for store
*
* @see Mage_Catalog_Block_Navigation
*/
?>
<a href="getUrl(”) ?>”>Homepage
getStoreCategories() as $_category): ?>
drawItem($_category) ?>
getStoreCategories() as $_category): ?>
getId(), array(163))) : ?> drawItem($_category) ?>
getChildHtml(‘cart_menu’) ?>
October 16, 2011 at 1:05 pm
?>
<a href="getUrl(”) ?>”>Homepage
getStoreCategories() as $_category): ?>
drawItem($_category) ?>
getStoreCategories() as $_category): ?>
getId(), array(163))) : ?> drawItem($_category) ?>
getChildHtml(‘cart_menu’) ?>
October 16, 2011 at 1:08 pm
wont let me paste the code, does it work on 1.6?
October 28, 2011 at 6:25 am
Hi Stuart, thanks very much for this. It works perfect in 1.6.0.0 too!, we’ve used this in a couple of themes and it works very fine.
Cheers!.-
October 28, 2011 at 2:57 pm
Awesome William
Thanks for confirning that it works in v1.6.0.0.
October 31, 2011 at 10:03 am
This worked for me in Enterprise v1.11.1.0
November 4, 2011 at 7:47 pm
Great to hear that it works in the enterprise edition of magento too Ryan, thanks for letting us know
November 16, 2011 at 6:44 am
thanks for this btw…if you are using the default theme the correct path is \app\design\frontend\base\default\template\catalog\navigation
December 28, 2011 at 6:19 am
It obviously works, but fixes like this create spaghetti code. Unfortunately this is not preventable since Magento really, really sucks. What about a simple checkbox called ‘visible in menu’ in the edit-category page. Noooo that would be too much work for the Magento developers, better spend our time developing a newsletter system that nobody’s gonna use..
February 28, 2012 at 8:46 am
works perfectly in Magento 1.6.1. Thanks for the help! This is great!
April 2, 2012 at 1:44 pm
I would like to konw how to add a div tag to the menu right before the second ul Is that possible? I can’t seem to find any place that has this info.
April 5, 2012 at 9:48 pm
Thanks for it, i wanna like exclude first category but show all it subcatgory in top menu navigation , how we can get it.