2

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!

2

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; ?> 
    
  • Thanks, Mukesh. This solution worked great but on a non-touch device only. Once a touch device (iPhone) was used, the menu became inoperable. Any ideas? – Dan Aug 16 '15 at 11:30
  • I have updated the answer. Can you try it again on touch devices? – Mukesh Chapagain Aug 16 '15 at 11:40
  • Works perfectly on all devices now! Thanks a lot for your help, Mukesh. – Dan Aug 16 '15 at 13:18
0

This answer helped point me in the correct direction, though make sure you are not using an extension which overrides default behavior. We had an extension Templates Master Navigation Pro and it was in a different location to edit in a similar way. Turning on template hints is always a good way to find out which template you need to edit and helped me end up finding the exact location to edit.

System -> Configuration -> (Advanced) Developer -> Template Hints (change Scope to correct view)

Though in our case I had to search our codebase for some identifying CSS selectors to find the Controller which was creating the proper object which was output after finding the template where that object was being rendered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.