Magento Forum

   
Add active-class element to Main Menu items for CMS pages? 
 
Meez
Member
 
Total Posts:  66
Joined:  2010-05-31
 

Hi,

I work on the site http://liefkado.nl/magento/

I made a static-block main-menu

In this static block ar two <li> tags

<li><a href="{{store direct_url="hoe-werkt-het"}}">Hoe werkt het?</a></li>
<
li><a href="{{store direct_url="vraag-offerte-aan"}}">Vraag offerte aan</a></li>

In the template file top.phtml I load the static-block main-menu. Now i have my CMS-pages in the Main Menu! This works fine.

<?php $_menu $this->renderCategoriesMenuHtml(0,'level-top'?>
<?php 
if($_menu): ?>

<div class="nav-container">
    <
ul id="nav">
        
<?php echo $_menu ?>
        <?php 
echo $this->getLayout()->createBlock('cms/block')->setBlockId('main-menu')->toHtml() ?>
    
</ul>
</
div>
<?php endif ?>

But how can i add an active-class element to the menu items? So i can style the active state by CSS.

Thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
magento.master
Jr. Member
 
Total Posts:  1
Joined:  2010-12-01
 

Hey Meez,

<?php foreach($_links as $_link): ?>
<li<?php if($_link->getIsActive():?> class="active" <?php endif; ?>><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>"<?php echo $_link->getLabel() ?></a> </li>
<?php endforeach; ?>

Try This!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Meez
Member
 
Total Posts:  66
Joined:  2010-05-31
 

thanks for the reply. But how do i integrate this in the existing code. I get an error with your code…

Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
therealro
Sr. Member
 
Total Posts:  102
Joined:  2010-04-09
 

Can somebody tell me how i can do this for the customer account menu?

I placed this:

<customer_account>
        <
reference name="customer_account_navigation">
            <
action method="addLink" translate="label" module="quickfaq"><name>My News</name><path>customer/account/news</path><label>My News</label></action>
        </
reference>
       </
customer_account>

But when i click on it, it show’s the news, but the menu item class isnt set to “active”.

Thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
nehashrivas
Jr. Member
 
Total Posts:  1
Joined:  2012-04-05
 

Hey meez,
hello! Do u got solution of your problem? If yes, plz let me know. I m having same problem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
michael_s
Jr. Member
 
Total Posts:  2
Joined:  2013-09-24
 

I need this solution badly. Can anyone help?

 
Magento Community Magento Community
Magento Community
Magento Community
 
michael_s
Jr. Member
 
Total Posts:  2
Joined:  2013-09-24
 

I think this is the solution.

jQuery(document).ready(function($){
var url = [removed]; // get current URL
$(’a[href="’+url+‘“]’).addClass(’active’); // add class of ‘active’ to selected links matching current url
});

Link

can anyone suggest me a better way?

 
Magento Community Magento Community
Magento Community
Magento Community
 
TomSmith
Sr. Member
 
Total Posts:  112
Joined:  2013-05-24
 

this extension will solved you problem :  MenuCreatorPro

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top