Magento – Add active class to CMS page links in Top menu (static block links)

magento-1.9static-blocktopmenu

In this Topmenu i have a custom home-link and some other CMS-links i insert through a Static Block.

How can i give those CMS-page menu items an active class?

— Update 1 —

I found this answer, but i can't get it to work?

I adjust app\design\frontend\mypackage\mytheme\template\page\html\topmenu.phtml like this:

<?php $_menu = $this->getHtml('level-top') ?>

<?php if($_menu): ?>
    <nav id="nav">
        <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('main-cms-links')->toHtml(); ?>
        </ol>
    </nav>

    <script>
        var currentPageId = '';
        <?php if (Mage::getSingleton('cms/page')): ?>
        currentPageId = '<?php echo Mage::getSingleton('cms/page')->getIdentifier(); ?>'
        <?php endif; ?>
        if (jQuery('#'+currentPageId).is('li')) {
           jQuery('#'+currentPageId).addClass('active');
        }
    </script>

<?php endif ?>

Best Answer

the best way would be to add some logic to the navigation to handle your additonal links.

However, easiest way would be to just give the links unique classes or ids and then activate them based on the body class:

body.cms-page-view.cms-about .about-us-button {color:red;}

body.cms-index-index.cms-home .introduction-button {color:red;}