Menu in sidebar: grandchildren show wrong menu (4 posts)

  1. Nunis
    Posted 8 years ago #

    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: http://dev.nunis.net/click/about/who-we-are/

    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.

  2. zedesino
    Posted 8 years ago #

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

  3. dustyseb
    Posted 7 years ago #

    any luck?

  4. boudewijnvl
    Posted 7 years ago #

    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 http://www.swingclose.nl

    hope this helps.

Topic Closed

This topic has been closed to new replies.

About this Topic