Support » Themes and Templates » List page menu with children and grandchildren

  • Okay so it’s been over a year since I made a WordPress theme and now I’ve started again but I’ve run into a problem with my menu on pages.

    This is my current page hierarchy (I’m still only testing hence the names)

    EDIT: Multi level UL->LI didn’t work so well here so I’ll just show you with * meaning child and **meaning grandchild

    This page
    	*Child 1
    		**Grandchild 1
    		**Grandchild 2
    	*Child 2
    		**Grandchild 3
    		**Grandchild 4
    		**Grandchild 5
    	*Child 3
    		**Grandchild 6
    Another page

    Now when I visit “This page” I want to show a link to “This page” (current) and all the direct childs (no grandchildren here) of “This page” like in this sketch:

    Now when i visit a “Child 1” of “This page” I want to show everything from above menu and all childs of “Child 1” (Grandchild 1 & 2) in a sub ul under “Child 1” like in this sketch:

    And now when I visit “Grandchild 1” I want to show the same menu as I did for “Child 1” only with “Grandchild 1” as current item instead like in this sketch:

    This is my current code based on the example in the codex for a slightly other type of menu but it isn’t working very well and absolutely not well for the godchildren.

    	$children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0");
    	$children .= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    	$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    	<div class="page-menu">
    	<?php echo $children; ?>
    <?php } ?>

    My plan is to have the menu as a sidebar on my page as you can see in the sketches.

  • The topic ‘List page menu with children and grandchildren’ is closed to new replies.