• I have been at this for hours and hours but cannot get it right. The closest I have got is showing 2 levels, but then the grandchild only shows it’s siblings, not parents.

    Basically..
    I have 3 levels:
    Parent
    Child
    Grandchild

    If I am on a Parent or Child page i want to show all pages of that tree, except grandchildren, e.g.

    About (selected page)
    – Page 1
    – Page 2
    – Page 3

    If i then click on a page that has grandchildren, it shows them, e.g.

    About
    – Page 1
    – Page 2 (selected page)
    — Page 2a
    — Page 2b
    – Page 3

    And if I click on a grandchild page, it shows the same as above, e.g.

    About
    – Page 1
    – Page 2
    — Page 2a (selected page)
    — Page 2b
    – Page 3

    I cannot for the life of me figure out how to do this!

    Any help is massively appreciated

Viewing 5 replies - 1 through 5 (of 5 total)
  • What theme is this?

    Thread Starter danhodkinson

    (@danhodkinson)

    This is a custom theme.

    Have you reviewed List_Sub-Pages?

    Thread Starter danhodkinson

    (@danhodkinson)

    Yep.

    If i could get it to spit out the tree consistently on all 3 levels (parent, child, grandchild) then I would just do it with CSS.

    The closest I have come to that is only showing the children and grandchildren, I can’t get it to include the parent in that.

    <?php
    							if(!$post->post_parent){
    								$children = wp_list_pages("depth=0&title_li=&child_of=".$post->ID."&echo=0");
    								echo "here";
    							}else{
    								$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    
    								if($post->ancestors)
    								{
    									$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 class="blank">
    									<?php echo $children; ?>
    								</ul>
    						<?php } ?>

    Personally, I use a variation of that code in functions.php:

    // Generate page tree
    function my_page_tree($this_page) {
    	$pagelist = '';
    	if( !$this_page->post_parent ) {
    		$children = wp_list_pages('title_li=&child_of='.$this_page->ID.'&echo=0');
    		if( $children ) {
    			$pagelist .= '<li class="current_page_item"><a href="'.  get_page_link($this_page->ID) .'">' . $this_page->post_title . '</a>';
    			$pagelist .= '<ul>' . $children . '</ul>';
    			$pagelist .= '</li>';
    		}
    	}
    	elseif( $this_page->ancestors ) {
    		// get the top ID of this page. Page ids DESC so top level ID is the last one
    		$ancestor = end( get_post_ancestors($this_page) );
    		$pagelist .= wp_list_pages('title_li=&include='.$ancestor.'&echo=0');
    		$pagelist = str_replace('</li>', '', $pagelist);
    		$pagelist .= '<ul>' . wp_list_pages('title_li=&child_of='.$ancestor.'&echo=0') .'</ul></li>';
    	}
    	return $pagelist;
    }

    which is then called in the page template using:

    if( function_exists( 'my_page_tree') ) :?>
    <div class="sub-pages"><h3><?php _e('Pages in this section', 'my');?></h3><ul>
    <?php echo my_page_tree($post);?></ul></div>
    <?php endif;?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Navigation (Parent, Child, Grandchild)’ is closed to new replies.