Support » Fixing WordPress » Dynamic menu highlighting with child-of-child pages

  • I’m using the solution described here to dynamically highlight top-level pages and their child pages:

    I have a top-level horizontal menu, with child pages in custom sidebars for each top-level page. Some of those sidebar menus are nested with two levels.

    The dynamic highlighting works great for the page and child page, but when on a child-of-child page, although the current page is highlighted, only the child-of-child level is displayed and the top-level page is not highlighted. What I want is for both levels of the sidebar menu to display, with the current page and the appropriate top-level page highlighted.

    The code I’m using is below. I’ve tried adding depth parameters, but that doesn’t seem to be the answer. Can anyone tell me how to fix this? I’m sorry I don’t have a link – this is a site under development on my localhost. Many thanks in advance for help.

    <?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 && is_page()) { ?>
    <?php echo $children; ?>
    <?php } else { ?>
    <?php } ?>
  • The topic ‘Dynamic menu highlighting with child-of-child pages’ is closed to new replies.