Jump to content

Current Menu Item (Child of Parent)


Lance O.
 Share

Recommended Posts

I've slightly modified the following code from the original found in the /site-default/head.inc file that is included in the installation of PW.

The page I am viewing is a child of "/team/" but $class isn't being added. What in the code below is incorrect?

<ul>

<?php

$team = $pages->get( "/team/" );

$children = $team->children;

foreach( $children as $child ) {

$class = $child === $page->rootParent ? " current-menu-item" : ''; // DOESN'T WORK

echo '<li id="menu-item-' . $child->id . '" class="nav-' . $child->name . ' menu-item menu-item-' . $child->id . $class . '"><a href="' . $child->url . '">' . $child->title . '</a></li>';

}

?>

</ul>

Link to comment
Share on other sites

Nothing wrong with the code, but it looks to me as the /team/ page isn't rendered in this code. What it does is output the children of /team/ not news itself. Have you anther code that's rendering the /team/ page?

Edit:

Ah I think you mean, the current page isn't active. Misunderstood that.

The get current page active you have to change it to this:

$class = $child === $page ? " current-menu-item" : '';
...
Link to comment
Share on other sites

  • 4 weeks later...

I've just found a variable or PW API value that seems to give me what I want, the trouble is I can't find it documented anywhere—anyone know if

$childSchild

is documented?

UhOh: Red herring, please pretend I didn't type that...

Edited by alan
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...