magento_logo

Adding CMS page links to top navigation in Magento


Hello friends,

I had a site running on magento 1.6.2 CE.

To add a menu item, first of all you need to find out where it is added into template file.

Following file is rendering categories as a menu on top navigation

app/design/frontend/base/template/catalog/navigation/top.phtml

Basically you need to modify this file and add links in list.

To make the changes upgrade proof, you should copy this file and paste it in your template directory

e.g. app/design/frontend/default/YourThemeName/template/catalog/navigation/top.phtml

Now you add a link as follow:

<!--?php $_menu = $this--->renderCategoriesMenuHtml(0,'level-top') ?>
<!--?php if($_menu): ?--></pre>
<div class="nav-container">
<ul id="nav">
	<li><a href="/">Home</a></li>
	<li><!--?php echo $_menu ?--></li>
</ul>
</div>
<pre>
<!--?php endif ?-->

But this way you will need to modify file each and every time when you want to modify links. So it is better to load a static CMS block. To do so, render two CMS block as shown bellow:

<!--?php if($_menu): ?--></pre>
<div class="nav-container">

</div>
<pre>
<!--?php endif ?-->

Now create those two CMS blocks in CMS -> Static Block -> Add New Block

Block identifier: navbar_links1

</pre>
<ul>
	<li><a href="{{store url=">Home</a></li>
	<li><a href="{{store url=">Introduction</a></li>
</ul>
<pre>

Similarly create another block for navbar_links2. Please Note that, when you edit them, HTML editor automatically adds

    tag surrounding it. You should remove it when ever you edit blocks.

Above trick was working perfectly until I upgrade my site to Magento Community addition 1.7.

I take a look around page.xml layout, and I noticed that, now magento is rendering menu from the following template file:

app/design/frontend/base/template/page/html/topmenu.phtml

So in order to work our trick, you need to modify above file by the way did it before.

First copy that file to following location:

app/design/frontend/default/YourTemplateName/template/page/html/topmenu.phtml

Make the same changes as we did it in top.phtml (show in listing no 2). Delete our old modified file app/design/frontend/default/YourThemeName/template/catalog/navigation/top.phtml as we don’t need it now. Flush the cache and you are done!

Your menu links will be back!

Advertisements

5 thoughts on “Adding CMS page links to top navigation in Magento

  1. Pingback: Problems, tips and tricks about Magento « Vikas Patel's Blog

  2. Heavy metal bands

    We’re a group of volunteers and opening a new scheme in our community. Your website offered us with valuable info to work on. You’ve done a formidable job and our
    whole community will be grateful to you.

    Reply
  3. Hangi Vpn

    yanı sıra, yerinin yol iş gerçekten önemli. Bağlı Kuruluşları alan tabanlı VPN’lerin komisyonları, deneyimi.

    ‘ noktadan-noktaya Tünelleme protokolü (PPTP): Bu protokol, veri şifrelemesi için
    sorumlu veri aktarımı ile VPN ağ.

    Reply

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s