peterpp Posted September 17, 2014 Share Posted September 17, 2014 Hi, In the menu, i am showing number of parent pages. On hovering on any menu, its child pages gets displayed. When i open any child page i want to show its parent page to be highlighted i.e activated. Plz guide me. Regards, Pravin Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 17, 2014 Share Posted September 17, 2014 Something like this: $search_in_parents = $page->parents->get($current_menu_page); if( !$search_in_parents->id ) echo "<li>…</li>"; // Not found else echo "<li class='highlight'></li>"; // Found in Parents If your childpages are only direct descendants you may use this to check for the one direct parent: if( $page->parent == $current_menu_page ) echo "It's the first Parent!"; Link to comment Share on other sites More sharing options...
peterpp Posted September 17, 2014 Author Share Posted September 17, 2014 Something like this: $search_in_parents = $page->parents->get($current_menu_page); if( !$search_in_parents->id ) echo "<li>…</li>"; // Not found else echo "<li class='highlight'></li>"; // Found in Parents If your childpages are only direct descendants you may use this to check for the one direct parent: if( $page->parent == $current_menu_page ) echo "It's the first Parent!"; HI LostKobrakai, Thanx for your reply. I pasting my code. I am using processwire with foundation zurb. So plz help me in modifying code. <section class="top-bar-section"> <?php echo "<ul class='left'>"; echo "<li class='has-dropdown'>"; $p = $pages->get(1001); echo "<a href='$p->url'>$p->title</a>"; echo "<ul class='dropdown'>"; $p = $pages->get(1001)->children; foreach( $p as $k ){ echo "<li><a href='$k->url'>$k->title</a></li>"; } echo "</ul>"; echo "</li>"; echo "</ul>"; ?> </section> Regards, Pravin Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 17, 2014 Share Posted September 17, 2014 $p = $pages->get(1001); would be the $current_menu_page of my example. If you want to change the class of the corresponding <li> element you would need to declare this variable before you echo this line: "echo "<li class='has-dropdown'>";" Link to comment Share on other sites More sharing options...
peterpp Posted September 17, 2014 Author Share Posted September 17, 2014 Hi LostKobrakai, It not working. Regards, Pravin Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 17, 2014 Share Posted September 17, 2014 <ul class='left'> <?php $menu_page = $pages->get(1001); if( $page->parent == $menu_page ) echo "<li class='highlight has-dropdown'>"; else echo "<li class='has-dropdown'>"; echo "<a href='$menu_page->url'>$menu_page->title</a>"; ?> <ul class='dropdown'> <?php foreach($menu_page->children as $child ){ echo "<li><a href='$child->url'>$child->title</a></li>"; } ?> <ul> </li> </ul> 1 Link to comment Share on other sites More sharing options...
peterpp Posted September 17, 2014 Author Share Posted September 17, 2014 Hi LostKobrakai, Thanx a lot..it worked for me.. Regards, Pravin Link to comment Share on other sites More sharing options...
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