Current Menu Item (Child of Parent)
Started by Lance, Jun 01 2012 10:26 PM
5 replies to this topic
#1
Posted 01 June 2012 - 10:26 PM
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>
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>
#2
Posted 02 June 2012 - 04:18 AM
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:
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" : ''; ...
@somartist | modules created | support me, flattr my work flattr.com
#4
Posted 28 June 2012 - 08:48 AM
$childSchild
UhOh: Red herring, please pretend I didn't type that...
Edited by alan, 28 June 2012 - 08:52 AM.
#5
Posted 28 June 2012 - 09:03 AM
What is $childSchild ? Don't think this even exists. How did you get to this?
@somartist | modules created | support me, flattr my work flattr.com
#6
Posted 28 June 2012 - 09:08 AM
Er. Um. I got it by using the power of typo [embarrassed sound of shuffling feet]
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













