PHP Magento Tips

Add Home link in Top Menu Navigation in Magento

Rate this posting:
{[['']]}

In Magento script, by default home link is not included in theme. So here you can see how easily you can add Home link in Main Menu.

Open app/design/frontend/rwd/default/template/page/html/topmenu.phtml and follow below steps.

Instead of below code:

<?php $_menu = $this->getHtml('level-top') ?>

<?php if($_menu): ?>
    <nav id="nav">
        <ol class="nav-primary">
            <?php echo $_menu ?>
        </ol>
    </nav>
<?php endif ?>

Add below code:

<?php $_menu = $this->getHtml('level-top') ?>
<?php
     $routeName = Mage::app()->getRequest()->getRouteName();
     $identifier = Mage::getSingleton('cms/page')->getIdentifier(); 
?>
<?php if($_menu): ?>
    <nav id="nav">
        <ol class="nav-primary">
            <li class="level0 home level-top <?php if($routeName == 'cms' && $identifier == 'home') {echo " active";}?>">
              <a href="<?php echo $this->getBaseUrl(); ?>" class="level-top">
                  <span><?php echo $this->__('Home'); ?></span>
              </a>
            <?php echo $_menu ?>
        </ol>
    </nav>
<?php endif ?>

Now you can see Home link will be added with active class. Now, you can add your css to apply background-color for home link.
Tag : Magento
0 Comments On "Add Home link in Top Menu Navigation in Magento"

Back To Top