Jump to content


Photo

Current Menu Item (Child of Parent)


  • Please log in to reply
5 replies to this topic

#1 Lance

Lance

    Distinguished Member

  • Members
  • PipPipPip
  • 69 posts
  • 26

  • LocationColumbus, Ohio

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>

#2 Soma

Soma

    Hero Member

  • Moderators
  • 3,187 posts
  • 1743

  • LocationSH, Switzerland

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:
$class = $child === $page ? " current-menu-item" : '';
...

@somartist | modules created | support me, flattr my work flattr.com


#3 Lance

Lance

    Distinguished Member

  • Members
  • PipPipPip
  • 69 posts
  • 26

  • LocationColumbus, Ohio

Posted 02 June 2012 - 07:21 AM

@Soma

That's it! And it makes sense now that I've had some sleep. ^_^ Thank you!

#4 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 405 posts
  • 118

  • LocationOttawa, Canada

Posted 28 June 2012 - 08:48 AM

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, 28 June 2012 - 08:52 AM.


#5 Soma

Soma

    Hero Member

  • Moderators
  • 3,187 posts
  • 1743

  • LocationSH, Switzerland

Posted 28 June 2012 - 09:03 AM

What is $childSchild ? Don't think this even exists. How did you get to this? :D

@somartist | modules created | support me, flattr my work flattr.com


#6 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 405 posts
  • 118

  • LocationOttawa, Canada

Posted 28 June 2012 - 09:08 AM

Er. Um. I got it by using the power of typo [embarrassed sound of shuffling feet] :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users