WordPress.org

Support

Support » Themes and Templates » [Resolved] wp_list_pages: list current top level page all siblings on ALL siblings

[Resolved] wp_list_pages: list current top level page all siblings on ALL siblings

  • Hi —

    Sorry, this must have been dealt with tons of times, but it’s hard to search forums for exactly what I want, and I’ve been fiddling with wp_list_pages for hours now. Any help much appreciated.

    I have :

    Top level page 1
    –Child page 1.1
    —-Grand child page 1.1.1
    —-Grand child page 1.1.2
    —-Grand child page 1.1.3
    –Child page 1.2
    —-Grand child page 1.2.1
    —-Grand child page 1.2.2
    —-Grand child page 1.2.3
    —-Grand child page 1.2.4
    Top level page 2
    –Child page 2.1
    —-Grand child page 2.1.1
    etc.

    Regardless of where I am within a given top level page tree, I need to display the current top level page tree (and only this one) with all siblings.

    I tried:

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

    …which works for top level and child pages, yet on grand child pages, I only see same level other grand child pages.

    IOW:

    Top level page 1 = OK (I see current top level + all sub levels)
    –Child page 1.1 = OK (I see current top level + all sub levels)
    —-Grand child page 1.1.1 = NOT OK as I only see 1.1.1 + 1.1.2 + 1.1.3, and not 1 and 1.1 (+child pages), 1.2 (+child pages) etc.

    THANKS!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Would this work as it seems:

    <?php
    if(!$post->post_parent){
    	// will display the subpages of this top level page
    	$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    }else{
    	// diplays only the subpages of parent level
    	//$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    
    	if($post->ancestors)
    	{
    		// now you can get the the top ID of this page
    		// wp is putting the ids DESC, thats why the top level ID is the last one
    		$ancestors = end($post->ancestors);
    		$children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
    		// you will always get the whole subpages list
    	}
    }
    
    if ($children) { ?>
    	<ul>
    		<?php echo $children; ?>
    	</ul>
    <?php } ?>

    I was wondering if you know what code to add to the original code to make it so you can see the parent page too, not just the children/sub-pages? hope that makes sense.
    thanks

    also, i don’t really need the drop down menu from my main horizontal header menu now that the subpages are showing up in sidebar. Do you know how to get rid of drop down menu in the main horizontal menu?
    thanks

    are you displaying this in the sidebar? There’s a neat little plugin which is not being further supported (by the looks of it) but I’ve been hacking at it and it works perfectly as you describe (if I read your post correctly)… have a look at:
    http://wordpress.dav3.net/
    for the subpage widget.

    if you go to:
    http://wordpress.dav3.net/my-book
    or
    http://wordpress.dav3.net/demo
    you can see it in action

    If you download the widget you’ll see the code is relatively easy to follow.

    @adbl… A useful (and working) snippet at the moment I needed it. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] wp_list_pages: list current top level page all siblings on ALL siblings’ is closed to new replies.