Magento 1.9 Menu – How to Make Parent Menu Item with Subcategories Not Clickable

magento-1.9menusubmenu

I need some help. I'm using Magento CE 1.9.2.1.

How can I make all parent categories of the top navigation menu non-clickable? Basically, I only want the menu categories that DON'T have any subcategories to be clickable.

I have 4 levels of categories and I only want the last one to be clickable.

I saw some tutorials but they all are for version 1.8 and lower. With the RWD theme it's all different now and I wasn't sure where to look.

Also, it would be great, as a bonus, to make the breadcrumb appear but not be clickable except the home link.

Thanks in advance!

Best Answer

Top Navigation Menu Non-Clickable

  • Open app/design/frontend/rwd/default/template/page/html/topmenu/renderer.phtml
  • Edit the following line of code:

    // COMMENT OUT THIS LINE
    //$html .= '<a href="'. $child->getUrl() .'" class="'. $outermostClassCode .' '. $_hasChildren .'">'. $this->escapeHtml($this->__($child->getName())) .'</a>';
    
    // ADD THESE LINES
    if (!empty($_hasChildren)) {
        $html .= '<a onclick="return false" style="text-decoration:none; cursor: default;" href="javascript:;" class="'. $outermostClassCode .' '. $_hasChildren .'">'. $this->escapeHtml($this->__($child->getName())) .'</a>';
    } else {
        $html .= '<a href="'. $child->getUrl() .'" class="'. $outermostClassCode .' '. $_hasChildren .'">'. $this->escapeHtml($this->__($child->getName())) .'</a>';
    }
    

Breadcrumb Non-Clickable

  • Edit this file app/design/frontend/base/default/template/page/html/breadcrumbs.phtml
  • You can add an IF condition to display link to Homepage only, like this:

    <?php if ($this->escapeHtml($_crumbInfo['label']) == 'Home'): ?>
            <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->escapeHtml($_crumbInfo['title']) ?>"><?php echo $this->escapeHtml($_crumbInfo['label']) ?></a>
    <?php else: ?>                      
            <a href="javascript:;" onclick="return false" style="text-decoration: none; cursor: default;" title="<?php echo $this->escapeHtml($_crumbInfo['title']) ?>"><?php echo $this->escapeHtml($_crumbInfo['label']) ?></a>
    <?php endif; ?> 
    
Related Topic