Magento – How to make “view all” link in topmenu with sub categories

categorymenusubmenu

I am trying to add a "view all" link to show under the main categories in my main menu.

Right now it would show:

category1
  – subcat1
  – subcat2
  – subcat3
category2
  – subcat1
  – subcat2
  – subcat3

I am trying to make it show:

category1
  – subcat1
  – subcat2
  – subcat3
  – view all
category2
  – subcat1
  – subcat2
  – subcat3
  – view all

Here is the menu code I am working with.

<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<div id="<?php echo $menu_type ?>" class="nav-container<?php if($menu_stay_on_top): echo " stay-top"; endif;?>">
    <div class="nav-inner hidden-tablet hidden-phone">
    <ul id="nav">
        <!-- <li class="menu-logo"><a href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); ?>"><img src="<?php echo $this->getSkinUrl('images/logo-small.png')?>" /></a></li> -->    
        <?php echo $_menu ?>
        <?php if (($block_custom_menu = $this->getLayout()->createBlock('cms/block')->setBlockId('block_custom_menu')->toHtml()) && $menu_type == 'wide-menu'): ?>
        <li class="nav-custom-link level0 level-top parent"><a class="level-top" href="#"><span><?php echo Mage::getModel('cms/block')->setStoreId(Mage::app()->getStore()->getId())->load('block_custom_menu')->getTitle(); ?></span></a>
        <ul class="level0">
            <div class="header-nav-dropdown-wrapper">
                <?php echo $block_custom_menu;?>
<li><a href="#"><span><?php echo Mage::getModel('cms/block')->setStoreId(Mage::app()->getStore()->getId())->load('block_custom_menu')->getTitle(); ?></span></a>
            </div>

        </ul>
        </li>
        <?php endif;?>
    </ul>
    </div> 

I just need to add a "view all" link at the bottom of the list of sub categories (only those 2 levels), which will just link to that sub category. So a duplicate link of the sub category but named view all.

Any guidance would be greatly appreciated.

Best Answer

I assume you need this for a version before 1.9 (because in 1.9 this happens by default).

You need to rewrite the method Mage_Page_Block_Html_Topmenu::_getHtml After the line $html .= $this->_getHtml($child, $childrenWrapClass); you need to add something like this:

if ($parentLevel == 1) {
   $html .= '<li><a href="<?php echo $child->getUrl()?>"'.Mage::helper('catalog')->__('view all').'</li>';
}
Related Topic