Lance O. Posted June 2, 2012 Posted June 2, 2012 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>
Soma Posted June 2, 2012 Posted June 2, 2012 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" : ''; ...
Lance O. Posted June 2, 2012 Author Posted June 2, 2012 @Soma That's it! And it makes sense now that I've had some sleep. Thank you!
alan Posted June 28, 2012 Posted June 28, 2012 (edited) 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 June 28, 2012 by alan
Soma Posted June 28, 2012 Posted June 28, 2012 What is $childSchild ? Don't think this even exists. How did you get to this?
alan Posted June 28, 2012 Posted June 28, 2012 Er. Um. I got it by using the power of typo [embarrassed sound of shuffling feet] 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now