• Hi

    I just thought I’d share this as it took me a couple of hours to work it out and I couldn’t find a post that directly addressed it.

    So you are dealing with pages not posts and you want a horizontal navbar (eg subject 1, subject 2, subject 3) so that when you are in (eg) subject 1 all of its children are visible in the sidebar and subject one remains highlighted as does the relevant child.

    In the header.php put the following code:

    <ul id="">
    <?php wp_list_pages('depth=1&title_li='); ?>

    And style in your css for a horizontal nav bar.

    This lists the top level pages.

    For the side navbar you put

    <?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 } ?>

    into the relevant sidebar.php

    This lists the children of the top level page, even if you are in the
    children.

    Then the css styles into your css file (the classes are automatically generated by WP.
    I’ve coloured orange for visibility!):

    li.current_page_item {background-color: #F4610F; color: white;}
    /*styles the children*/
    	li.current_page_parent {background-color: #F4610F; color: white;}
    /*styles the parents*/

    It’s all pretty much covered here

    Hope this saves someone some time…

Viewing 1 replies (of 1 total)
  • Thread Starter juliageek

    (@juliageek)

    OK, so what this fails to do is to show the direct ancestors of a third level page in the left hand nav bar. EG:

    • main parent
    • child
    • grandchild

    You only want the main parent highlighted in the menu bar (not visible at all in the side bar).
    You can see the grandchild when you are in the child, but when you are in the grandchild you can’t see the child, so there’s no way back via the menu.

    Well, after more hours I came across a brilliant solution to this using Foldpages. it is covered here.
    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘horizontal parent navbar with vertical children in sidebar’ is closed to new replies.