Support » Fixing WordPress » Menu in sidebar: grandchildren show wrong menu

  • Hi everyone,

    I’m setting up a corporate page using WordPress as a CMS and I have a slight problem with sub-sub pages (grandchildren).

    First of all, you can see the site here:

    As you can see, I have a parent menu in the header, which is fine.
    I then I have child pages in the sidebar, which is also fine. The sidebar uses this code.

      $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) { ?>
    <h2>In this section:</h2>
    <ul id="submenu">
      <?php echo $children; ?>
    <?php } ?>

    The problem now is that when you go into a grandchild page (such as ‘Management’), you can no longer see the parents in the sidebar. Obviously what I want is to show all children and grandchildren for the respective parent chosen from the header.

    Can anyone please help with this? I’d so much appreciate it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello, i have the same problem, did you maybe find the solution?
    i tweak this code a litle and get grandchildren n chilrden page but i can kee them visible when i’m on grandchildren page.

    here is the code:


    $grandchildren = wp_list_pages(“title_li=&child_of=”.$post->children.”&echo=0″); else
    $grandchildren = wp_list_pages(“title_li=&child_of=”.$post->ID.”&echo=0″);
    if ($grandchildren)

    { ?>

      <?php echo $grandchildren; ?>

    <?php } ?>

    any luck?

    Hi everybody,

    Ik had the same problem and solved it like this:

    $children = wp_list_pages("title_li=&amp;child_of=".getTopParentPostid($post->ID)."echo=0");

    using the function:

    //return the id of the top parent page base on a page_id
    function getTopParentPostID($myid){
    	$mypage = get_page($myid);
            $myid = $mypage->post_parent;
            $mypage2 = get_page($myid);
    	if ($mypage2->post_parent == 0){
    		return $myid;
    		return getTopParentPostID($myid);

    you can se the result at

    hope this helps.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Menu in sidebar: grandchildren show wrong menu’ is closed to new replies.