1

Topic: Active menu page

Hi, it want have different styles on active and inactive menu links. Just like wolf cms homepage does.
Lets say I have 3 links: Home, About, Contact. If I am on contact page i want link to have active class. Hows that possible?

Last edited by Wolf (2009-11-24 11:24)

Thumbs up

2

Re: Active menu page

<?php
$home_childs = $this->find('/')->children();
foreach($home_childs as $menu):
?>
<li class="active"><?php echo $menu->link(); ?></li> // active or inactive???
<?php endforeach; ?>

Thumbs up

3

Re: Active menu page

Wolf wrote:

If I am on contact page i want link to have active class. Hows that possible?

Hi Wolf: I assume you mean you want the link tag to contain your "active" class, and not the anchor tag as it is in Wolf by default.

Here is the standard navigation code, but with the conditional "active" (or "current") class moved to the <li>:

<div id="nav">
    <ul>
      <li<?php echo url_match('/') ? ' class="current"': ''; ?>><a href="<?php echo
URL_PUBLIC; ?>">Home</a></li>
<?php foreach($this->find('/')->children() as $menu): ?>
      <li<?php echo in_array($menu->slug, explode('/', $this->url)) ? ' class="current"': null; ?>><?php echo $menu->link($menu->title); ?></li>
<?php endforeach; ?> 
    </ul>
</div> <!-- end #navigation -->

You will need to adjust that for your own situation -- but does that give you what you need to get going? Let us know how it goes!

4

Re: Active menu page

Yes, thank you for you help. It worked.. I made this one myself..

<?php
$home_childs = $this->find('/')->children();
foreach($home_childs as $menu):
?>
<li class="<?php if ($menu->url == $this->url){echo"active";}else{echo"inactive";} ?>"><?php echo $menu->link(); ?></li>
<?php endforeach; ?>

I like your better though

Last edited by Wolf (2009-11-24 17:11)

Thumbs up

5

Re: Active menu page

Yes, you're one is much better, especially when using sub-menus as well. Thank you! smile

Thumbs up