Wednesday, January 30, 2013

How to add new link in menu to new CMS page created in magento

Magento 1.5x cheatsheet series
So, you created new link in your fresh magento installation. Maybe you wrote simple FAQ or billing and shipping information for your customers. And now there is no tool to create link to your newly written masterpiece. As far as my research took me, there actually is no such tool built into magento. Little bit of coding on other hand, can solve this problem quickly.
All you have to do is edit file top.phtml.
If you edit built in theme of magento, then location of file is: /app/design/frontend/base/default/template/catalog/navigation
if you work on your own theme, then file should be in folder:
app/design/frontend/your_theme_name/default/template/catalog/navigation

Once you open file for edit, you should locate code
 <div class="nav-container">     
  <ul id="nav">      
  <?php echo $_menu ?>  
   you add code of your new menu object here  
 </ul>  
And code to add is:
 <a href="<?php echo $this->geturl('about-magento-demo-store') ?>">   
 <?php echo $this->__('About Us')?></a>   
Where 'CMS PAGE IDENTIFIER' is to be changed out with your page identifier. Page identifier in CMS is URL Key, for instance About Us is 'about-magento-demo-store'.
So full code of menu with one object which would connect to CMS page "about us" would be:

  <div class="nav-container">     
  <ul id="nav">     
   <?php echo $_menu ?>   
   <a href="<?php echo $this->geturl('about-magento-demo-store') ?>">   
   <?php echo $this->__('About Us')?></a>   
  </ul>   

No comments: