• I used the Dynamic Menu Highlighting script to create active states for my nav based on the page being viewed. Now, I have child pages that I also want to show the active state to reflect what “section” a visitor is in.

    Example: If “web design” is a child page of “portfolio”, portfolio would be highlighted in the nav.

    I can do this using OR statements in my php, but that gets messy and has to be updated if a new child-page is added. Here is the code I came up with the messy way:

    if ( is_page('porfolio') || is_page('web-design') || is_page('print-design') ) { $current = 'n-festival-info'; }

    Does anyone have a solution that would solve this dynamically? I tried using the if($post->post_parent) code that I use to build out sub-navs when child-pages are detected, but that got messed up quickly.

    Any ideas?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter kcomphlint

    (@kcomphlint)

    bump

    I would also like to know the answer to this question. I’m using an image navigation and I’d like to keep the parent page (a category page in this instance) highlighted while on a child page.

    I would also like to know how to do this, I’ve using text navigation.

    Any ideas?

    Ta!

    Kcomphlint,

    I would like to know how to do this as well, but right now I’m willing to settle for the messier version.

    I have a horizontal navigation list like this:

    <div id="menu">
    		<ul id="navlist">
    <li<?php if (is_home()) { echo " class=\"current\""; }?>><a href="<?php bloginfo('url') ?>">Home</a> |  </li>
    <li<?php if (is_page('5')) { echo " class=\"current\""; }?>><a href="<?php bloginfo('url'); ?>/about">About</a> | </li></ul></div>

    And a sidebar menu that lists children of a page:

    <div id="navibar">
    	<div class="links">
    		<ul>
    <li>
    <?php
      if($post->post_parent)
      $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
      else
      $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
      if ($children) { ?>
      <ul>
      <?php echo $children; ?>
      </ul>
      <?php } ?>
    </li></ul></div></div>

    I want the top-level parent highlighted when I’m on a child page.

    Would your messy php code work with this?

    Thanks.

    This article was very helpful for me: https://www.darrenhoyt.com/2008/02/12/creating-two-tiered-conditional-navigation-in-wordpress/

    I think it solved my problem.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Dynamic Highlighting Menu for Child Pages’ is closed to new replies.