4

It's pretty easy to add some types of links to top menu using this method: http://www.magentocommerce.com/knowledge-base/entry/adding-page-links-in-the-navigation-bar

But I cannot figure out how to add a simple home page link. The above method does not seem to work. It seems that the method requires some type of URL, and if it's left blank or a "/" is used, Magento makes up a link that does not work.

I have custom theme, based on the RWD theme, with a local.xml file. I have tried to add code suggested from various websites, to add a new top link, but the code seems to not work for Magento 1.9.

I have been experimenting with the renderer.phtml file in my theme, with no luck.

Any suggestions for adding a link in the top links of Magento 1.9, especially a home page link?

  • 1
    The link in this question appears to be dead. – quickshiftin Apr 27 '15 at 17:20
14

First copy topmenu.phtml from

/app/design/frontend/rwd/default/template/page/html/

Save this file as topmenu.phtml to

/app/design/frontend/YOUR PACKAGE/YOUR THEME/template/page/html/

Edit this file within lines 38-40, paste the following:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('home-link')->toHtml(); ?>

To create:

<ol class="nav-primary">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('home-link')->toHtml(); ?>
<?php echo $_menu ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('post-menu-links')->toHtml(); ?>
</ol>

Save and re-upload this file.

Create a CMS > Static Block, named home-link enter the following into your block (Hide Editor, as needed):

<li class="level0 nav-1 parent"><a href='{{config path="web/unsecure/base_url"}}' title='Home Page' class='level0'>Home</a></li>

Note: I leave all of the class names consistent with 1.9. Feel free to adjust class names as needed.

Save your new Static Block.

Create a CMS > Static Block, named post-menu-links Enter the following into your block (Hide Editor, as needed):

<li class="level0 nav-1 parent"><a href="CUSTOMPATH-1.HTML" title="LINK TITLE #1" class="level0">LINKNAME #1</a></li>
<li class="level0 nav-1 parent"><a href="CUSTOMPATH-2.HTML" title="LINK TITLE #2" class="level0">LINKNAME #2</a></li>
<!--  and so on, as needed ...  -->

Save your new Static Block.

Be sure to clear the cache and refresh your browser.

  • Works great. Thank you very much. I also found that if I duplicate snippet, I am able to create menu items after the category items created by Magento (instead of just before them). – Andrew Jun 20 '14 at 21:44
  • Glad it worked for you. I also created a duplicate block for post menu items. Please accept the answer as the correct one. – Joshua34 Jun 20 '14 at 21:47
  • I'm not seeing the block for post menu items. Would be great to see this, as I am having some minor issues with what I have. Also, I did accept your answer as the correct one - please let me know if it is not showing up this way. – Andrew Jun 21 '14 at 22:37
  • Thanks Andrew. I added more detail to my answer for post menu items. – Joshua34 Jun 21 '14 at 22:51
  • +1 still lacks active state. Any idea ? – Suman K.C Apr 23 '15 at 8:24
6

Below code will add a Custom home link under Account drop-down in RWD theme.

app/design/frontend/rwd[Package name]/[THEME NAME]/layout/local.xml

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
    <default>
        <reference name="root">
        <reference name="top.links">
            <action method="addLink" translate="label title">
                <label>Custom Home Link</label>
                <url>home</url>
                <title>Custom Home Link</title>
                <prepare/>
                <urlParams/>
                <position>10</position>
            </action>
        </reference>
        </reference>
    </default>
</layout>

Below code will add custom home link before Account dropdown.

app/design/frontend/rwd[package name]/[theme name]/template/header.phtml

<a href="<?php echo $this->getBaseUrl(); ?>" class="skip-link skip-home">
    <span class="icon"></span>
    <span class="label"><?php echo $this->__('Home'); ?></span>
</a>
  • My apologies for not explaining myself very well. I am trying to insert a home page link within the main menu/navigation. In other words, a link in-line with the other menu links (categories, etc). I'm trying to get it in the the menu and showing on desktop and mobile menus. Thank you for any suggestions. – Andrew Jun 9 '14 at 14:52
0

I follow this tutorial to add an external link to my Magento homepage https://magentoexplorer.com/how-to-add-custom-link-or-homepage-link-to-magento-top-menu

Step 1:

go to app/design/frontend/rwd/default/template/page/html/topmenu.phtml

Look for

<nav id="nav">
        <ol class="nav-primary">
            <?php echo $_menu ?>
        </ol>
    </nav>

and add this line into OL tag

<li><a href="<?php echo $this->getUrl('') ?>"><?php echo $this->__('Home') ?></a></li>

Now it's like this

    <nav id="nav">
        <ol class="nav-primary">
<li><a href="<?php echo $this->getUrl('') ?>"><?php echo $this->__('Home') ?></a></li>
            <?php echo $_menu ?>
        </ol>
    </nav>

Now the menu should be like this

enter image description here

you can changes url target in getUrl('your url') and anchor text in $this->__('your displayed text')

-1

To add links to top navigation menu. You can change page/html/topmenu.phtml file:

    <?php $_menu = $this->getHtml('level-top') ?>
    <?php if($_menu): ?>
    <div class="nav-container">
        <ul id="nav">

<!-- THIS IS WHERE YOU MAKE THE CHANGE -->
            <li><!--LINK TO YOUR PAGE HERE--></li>
<!-- CHANGE ENDS HERE -->
            <?php echo $_menu ?>
        </ul>
    </div>
    <?php endif ?>

You can add any link to top links in magento using the following code:

<reference name="top.links">
                <action method="addLink">
                    <label>Home</label>
                    <title>Home</title>
                    <!-- You can google for various url helpers to get url to default magento pages or you can write your own url in <url> </url> tag-->
                    <urlParams helper="core/url/getHomeUrl"/><urlParams>
                </action>
</reference>
  • I couldn't get that to work yet. It could be that I have the wrong markup in my local.xml file, although some of what I have in there is working (a block to remove footer links). I am trying to figure out how to post the code I have in this comment, but it won't seem to let me. – Andrew Jun 7 '14 at 16:18
  • edit your question and post your code there – Rojan Shrestha Jun 7 '14 at 16:19
  • I have my local.xml file setup and I'm able to use the first code example from this post: – Andrew Jun 8 '14 at 2:15
  • I have my local.xml file setup and I'm able to use the first code example from this post (it removes the footer links): magento.stackexchange.com/questions/22067/… Any ideas on how to integrate the code suggested by Rojan Shrestha (in this post) into that first example (on the other post)? I've been working on this for hours, trying different variations, and whatever I do results in nothing or a broken local.xml file. Thanks for any help. – Andrew Jun 8 '14 at 2:23
  • Let me try it again: Rojan, the code you suggested seemed to break the layout file, local.xml, which I have in my custom theme. I have successfully installed other actions to the layout file, without any issues. So I don't think it's a syntax error on my part. All of the searches I done on adding a simple link to top links, seem to be now outdated and do not work. My guess is this has to do with the changes in Magento 1.9. For example, the top links are now managed in renderer.phtml, not top.phtml. I'll keep searching, but any suggestions would be great. An action for local.xml would be great. – Andrew Jun 8 '14 at 4:36

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.