Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How Do I—Limit the Number of Categories Listed on the Top Navigation Bar
 
dcross
Jr. Member
 
Total Posts:  15
Joined:  2009-12-04
 

I am trying to limit the number of categories displayed on the top navigation bar so that they do not wrap around the menu bar.  I have a left navigation block where I want ALL of my categories to be display, but only want to specify a few key categories on the top nav bar.

Does anyone know how to limit the number of categories that the top navigation bar displays?  Is it possible to convert the handful of categories that I want to display on the top navigation bar over to links to the individual category product pages?

I have found one other post that tried to use a little PHP code in the top.phtml file to count to a specific number of categories displayed and then stop, but I was unable to get it to work.

Can anyone out there assist?  I know there has to be others that are fighting having too many categories to properly display on the top navigation bar.


Thanks,
dcross

 
Magento Community Magento Community
Magento Community
Magento Community
 
yban38
Member
 
Avatar
Total Posts:  54
Joined:  2009-02-06
Grenoble, France
 

hello,
i think you can do that with menu.css.

something like this :
#nav li.nav-category-code { display:none; }

for each category you wouldn’t show.

 
Magento Community Magento Community
Magento Community
Magento Community
 
dcross
Jr. Member
 
Total Posts:  15
Joined:  2009-12-04
 

Thanks, I will give it a try!

dcross

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rooni
Sr. Member
 
Total Posts:  87
Joined:  2009-03-25
England
 

You have to add a php line in top.phtml to do this

app/design/frontend/default/youretheme/template/catalog/navigation/top.phtml

This is my top.phtml code:

<ul id="nav">

        <
li onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)" class="level0 nav- parent"><span><a href="<?php echo $this->getUrl('')?>"><?php echo $this->__('Home'?></span></a></li>
               
<?php $i=0$j=0?>
              <?php 
foreach ($this->getStoreCategories() as $_category): ?>
              <?php 
if ($i>9): continue; endif; ?>                    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Limiting categories to 9
              <?php 
echo $this->drawItem($_category?>

        <?php  $i
++; endforeach ?>
       
</ul>

Hope this helps

 
Magento Community Magento Community
Magento Community
Magento Community
 
dcross
Jr. Member
 
Total Posts:  15
Joined:  2009-12-04
 

Haroon,

I cannot thank you enough for this small snippet of code, it fixed me 100%!  Many thanks to you.

Cheers,
Doug

 
Magento Community Magento Community
Magento Community
Magento Community
 
hartus
Jr. Member
 
Total Posts:  13
Joined:  2011-04-21
 

I\’m not a great php Developer but I\’m trying to adapt this to my custommenu. Anyone could help ?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top