WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Nunis
    Member
    Posted 6 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.

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

    <?php
    if($post->children)

    $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
    Member
    Posted 5 years ago #

    any luck?

  4. boudewijnvl
    Member
    Posted 5 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;
    	}
    	else{
    		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