Magento Forum

Page 1 of 2
Adding links to top menu
 
aimon
Jr. Member
 
Total Posts:  4
Joined:  2008-10-29
 

Hey Guys,

I am having real troubles adding links to the top menu across the site and would appreciate you heko.

I have included the links in the app/design/frontend/default/default/template/catalog/navigation/top.phtml as described in
http://www.magentocommerce.com/wiki/how-to/add_home_link_to_menu_bar

I can only get the About Us page to show up and this is only in the catalog pages. How can i add menu items across the site (including the homepage and CMS created pages?

My code is as follows

<div class="header-nav-container">
<div class="header-nav">
<h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
<ul id="nav">
<li><a href="<?php echo $this->getUrl('home')?>"><?php echo $this->__('Home') ?></a></li>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
<li><a href="<?php echo $this->getUrl('contactus')?>"><?php echo $this->__('Contact Us') ?></a></li>
<li><a href="<?php echo $this->getUrl('faq')?>"><?php echo $this->__('FAQ') ?></a></li>
<li><a href="<?php echo $this->getUrl('aboutus')?>"><?php echo $this->__('About Us') ?></a></li>
</ul>
</div>
<?php echo $this->getChildHtml('topLeftLinks') ?>
</div>

Thanks

Aimon

 
Magento Community Magento Community
Magento Community
Magento Community
 
cwsites
Jr. Member
 
Avatar
Total Posts:  5
Joined:  2008-12-24
Atlanta, GA
 

It worked for me, I would say to make sure that your

getUrl('contacts')
is pointed at the right page and that it’s enabled. I know by default the contact us page is “contacts” not “contactus”

Not sure about the others.

 
Magento Community Magento Community
Magento Community
Magento Community
 
fiber0pti
Sr. Member
 
Total Posts:  81
Joined:  2008-07-10
 

I’m also having problems with this. I can’t get the about magento page to show up as a menu item without totally destroying the entire output. I’ve added

<li><a href="<?php echo getUrl('about-magento-demo-store') ?>"><?php echo $this->__('About'?></a></li>

to the file: top.phtml

How do I add menu items to link to CMS content?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Raptor Commerce (toby)
Sr. Member
 
Total Posts:  180
Joined:  2009-01-31
 
fiber0pti - 22 May 2009 08:34 AM

I’m also having problems with this. I can’t get the about magento page to show up as a menu item without totally destroying the entire output. I’ve added

<li><a href="<?php echo getUrl('about-magento-demo-store') ?>"><?php echo $this->__('About'?></a></li>

to the file: top.phtml

How do I add menu items to link to CMS content?

@fiberOpti - you might want to look at our extension Custom menus which allows you build your own menus, in addition to the standard Magento product categories. We also offer another extension, Supermenu which builds on the functionality of Custom menus and allows you to display multi column drop down menus as used on sites like asos.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sajid iqbal
Jr. Member
 
Total Posts:  14
Joined:  2009-12-08
 

All links place in above mentioned way worked for me. The problem is how can i get active states for these links?

 
Magento Community Magento Community
Magento Community
Magento Community
 
mazy
Jr. Member
 
Total Posts:  17
Joined:  2009-04-24
 

I would also like to know how o get active links working.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Germán W
Jr. Member
 
Total Posts:  22
Joined:  2010-02-19
 
\"mazy\" -

I would also like to know how o get active links working.

I got active links to work this way:

<li class="level0 nav-5<?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl().'contacts/'):?> active<?php endif;?>">
<
a href="<?php echo $this->getUrl('contacts')?>"><?php echo  $this->__('Contact Us'?></a>
</
li>

What the “php if” does is check if the current URL is the same as this page url and if so it adds the “active” class to the link.

So the .\’contacts\’ part should be what comes after /index.php/ in you pages\’ URL.

 
Magento Community Magento Community
Magento Community
Magento Community
 
hancoha
Jr. Member
 
Total Posts:  20
Joined:  2010-04-25
Auburn, Alabama
 
Germán W - 23 April 2010 02:45 PM

\"mazy\" -
I would also like to know how o get active links working.

I got active links to work this way:

<li class="level0 nav-5<?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl().'contacts/'):?> active<?php endif;?>">
<
a href="<?php echo $this->getUrl('contacts')?>"><?php echo  $this->__('Contact Us'?></a>
</
li>

What the “php if” does is check if the current URL is the same as this page url and if so it adds the “active” class to the link.

So the .\’contacts\’ part should be what comes after /index.php/ in you pages\’ URL.

This worked great. Is it important to have the / after the page url? For example about-us/. It works just fine for me using about-us but I didn’t know if there was some issue with that. Thanks,

 
Magento Community Magento Community
Magento Community
Magento Community
 
mancourt
Member
 
Avatar
Total Posts:  34
Joined:  2010-08-03
 

I’m trying to get this to work in Magento 1.4.1 by editing top.phtml using a page “upcoming-sales.html”.

<li class="level0 nav-5<?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl().'upcoming-sales.html/'):?> active<?php endif;?>">
<
a href="<?php echo $this->getUrl('upcoming-sales.html/')?>"><?php echo  $this->__('Upcoming Sales'?></a>
</
li>

It’s not adding a class, is my code wrong or does this hack not work for 1.4.1?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
raska__
Member
 
Total Posts:  42
Joined:  2009-05-24
 

Hi,
I think that this is a cache problem.
If you disable Block html cache from admin you will see correct, but is not the solution.....

bye

 
Magento Community Magento Community
Magento Community
Magento Community
 
chiefair
Mentor
 
Avatar
Total Posts:  1848
Joined:  2009-06-04
 

For 1.4.1.1

For enabling dynamic top menu and navigation elements, instead of disabling the BLOCK_HTML cache, disable caching of the block element altogether.

Find /app/code/core/local/Mage/Catalog/Block/Navigation.php and save it to your local code store.

Look for the _construct() code block

protected function _construct()
    
{
        $this
->addData(array(
            
'cache_lifetime'    => false,
            
'cache_tags'        => array(Mage_Catalog_Model_Category::CACHE_TAGMage_Core_Model_Store_Group::CACHE_TAG),
        )); 
    
}

And comment out the CACHE_TAG stuff as follows:

protected function _construct()
    
{
    
/*    $this->addData(array(
            'cache_lifetime'    => false,
            'cache_tags'        => array(Mage_Catalog_Model_Category::CACHE_TAG, Mage_Core_Model_Store_Group::CACHE_TAG),
        )); */
    
}

This should force Magento to create a fresh version of Catalog_Block_Navigation each time page reload occurs, allowing you to use Block HTML caching and getting back some speed while enabling the fancy stuff.

EDIT: A more sophisticated and fully modularized way of doing this cache prevention over here

 
Magento Community Magento Community
Magento Community
Magento Community
 
freshwebs
Sr. Member
 
Total Posts:  153
Joined:  2008-05-27
Leicestershire, UK
 
chiefair - 31 October 2010 10:15 AM

For 1.4.1.1

For enabling dynamic top menu and navigation elements, instead of disabling the BLOCK_HTML cache, disable caching of the block element altogether.

Find /app/code/core/local/Mage/Catalog/Block/Navigation.php and save it to your local code store.

Look for the _construct() code block

protected function _construct()
    
{
        $this
->addData(array(
            
'cache_lifetime'    => false,
            
'cache_tags'        => array(Mage_Catalog_Model_Category::CACHE_TAGMage_Core_Model_Store_Group::CACHE_TAG),
        )); 
    
}

And comment out the CACHE_TAG stuff as follows:
protected function _construct()
    
{
    
/*    $this->addData(array(
            'cache_lifetime'    => false,
            'cache_tags'        => array(Mage_Catalog_Model_Category::CACHE_TAG, Mage_Core_Model_Store_Group::CACHE_TAG),
        )); */
    
}

This should force Magento to create a fresh version of Catalog_Block_Navigation each time page reload occurs, allowing you to use Block HTML caching and getting back some speed while enabling the fancy stuff.

Thanks for the heads-up on this one - I was struggling to figure out what was going on. Works on 1.3.2.4 too.
Regards,
Eddie

 
Magento Community Magento Community
Magento Community
Magento Community
 
ArashNL
Jr. Member
 
Total Posts:  11
Joined:  2010-06-18
 

I just change my code to this and it works fine smile. Of course Flush the cach was needed. im using magento 1.4.1.1. There is no activation piece of code needed.

<?php $_menu = \\\'\\\'?>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php $_menu .= $this->drawItem($_category) ?>
<?php endforeach ?>
<?php if ($_menu): ?>
<div class=\\\"nav-container\\\">
<ul id=\\\"nav\\\">
<li class=\\\"level0 first nav-home\\\"><a href=\\\"<?php echo $this->getUrl() ?>\\\"><span><?php echo $this->__(\\\'Home\\\') ?></span></a></li>

<li class=\\\"level0 nav-1 parent\\\"><a href=\\\"<?php echo $this->getUrl(\\\'contacts\\\')?>\\\"><span><?php echo $this->__(\\\'Contact\\\') ?></span></a></li>

<?php echo $_menu; ?>
<?php echo $this->getLayout()->createBlock(\\\'cms/block\\\')->setBlockId(\\\'menu\\\')->toHtml() ?>
</ul>
</div>
<?php endif; ?>

Don’t forget to ignore this sign \\\ in the code.
if you want to put the contact menu after your home and product’s category menu. You should put your codes as follow:

<?php $_menu = ''?>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php $_menu .= $this->drawItem($_category) ?>
<?php endforeach ?>
<?php if ($_menu): ?>
<div class="nav-container">
<ul id="nav">
<li class="level0 first nav-home"><a href="<?php echo $this->getUrl() ?>"><span><?php echo $this->__('Home') ?></span></a></li>
<?php echo $_menu; ?>
<li class="level0 nav-1 parent"><a href="<?php echo $this->getUrl('contacts')?>"><span><?php echo $this->__('Contact') ?></span></a></li>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('menu')->toHtml() ?>
</ul>
</div>
<?php endif; ?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
alexmargineanu
Jr. Member
 
Avatar
Total Posts:  26
Joined:  2009-10-15
London
 

A cleaner way to disable block caching for Navigation.php,

Alex.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagePsycho
Mentor
 
Avatar
Total Posts:  1702
Joined:  2009-06-23
 

If you want to edit the top links using a single local.xml layout file then i recommend to use the following technique:
http://classyllama.com/development/magento-development/editing-magentos-top-links-the-better-way/

It just works great. I love the way.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Magazento
Sr. Member
 
Avatar
Total Posts:  155
Joined:  2010-01-08
Russia,Volgograd
 

look at this extension i hope you will like it
http://www.magentocommerce.com/magento-connect/Magazento/extension/6139/magazento_megamenu

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2