Add Home Link with functional active state to Menu Bar (Alternative Method)

Last modified by rpotterjr on Thu, June 24, 2010 17:02
Source|Old Revisions  

This is an old revision of the document!


:::: TRIED THIS AND IT ADDS THE LINK, BUT THE ACTIVE STATE DOES NOT FUNCTION CORRECTLY ::::

Special Note to the person(s) responsible for this page. Myself and many others have attempted to use this code snippet to get the result explained with an active state, but have been unable to get the active state to work. The link does work as far as pointing to exsisting cms page or external pages, but the “active” state does not work at all. Page refreshes and all links adjust back to original state.


Add Home Link to Menu Bar

For the Home link in the menu bar of the main template you can add some code to one of the template files.

Find the file called top.phtml in app/design/frontend/default/default/template/catalog/navigation/ and make the following change:

  1. <div class="header-nav-container">
  2.     <div class="header-nav">
  3.         <h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
  4.         <ul id="nav">
  5.  
  6.         <!-- HOME BUTTON HACK -->
  7.         <li><a href="<?php echo $this->getUrl('')?>"><?php echo $this->__('Home') ?></a></li>
  8.         <!-- HOME BUTTON HACK -->
  9.  
  10.         <?php foreach ($this->getStoreCategories(10) as $_category):?>
  11.             <?php echo $this->drawItem($_category) ?>
  12.         <?php endforeach ?>
  13.         </ul>
  14.     </div>
  15.     <?php echo $this->getChildHtml('topLeftLinks') ?>
  16. </div>

If you want the home button to behave as te rest (get the active class when activated) change the above code to the following: (beware this is just as an hack as the previous example, but still, it works)

  1. <div class="header-nav-container">
  2.     <div class="header-nav">
  3.         <h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
  4.         <ul id="nav">
  5.  
  6.     $_SERVER['REQUEST_URI'] == '/' ? $root = 'active' : $root = '';
  7.  
  8.         <!-- HOME BUTTON HACK -->
  9.         <li class="<?php echo $root ?>"><a href="<?php echo $this->getUrl('')?>"><?php echo $this->__('Home') ?></a></li>
  10.         <!-- HOME BUTTON HACK -->
  11.  
  12.         <?php foreach ($this->getStoreCategories(10) as $_category):?>
  13.             <?php echo $this->drawItem($_category) ?>
  14.         <?php endforeach ?>
  15.         </ul>
  16.     </div>
  17.     <?php echo $this->getChildHtml('topLeftLinks') ?>
  18. </div>

Two things re the second version of the code

1.

  1.    $_SERVER['REQUEST_URI'] == '/' ? $root = 'active' : $root = '';

should be :

  1.   <?php $_SERVER['REQUEST_URI'] == '/' ? $root = 'active' : $root = ''; ?>

2.

If your magento code is not in the root directory of your website then you need to add the path in so change:

  1. $_SERVER['REQUEST_URI'] == '/'

to

  1. $_SERVER['REQUEST_URI'] == '/magentopath/'

where “magentopath” is the subdirectory where your magento code is.

Related Tags:  Link Home Magento 1.5



 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs