• trying to get children and grandchildren to display within the same pages. I have bene trying to figure this out forever…

    i have a main parent “DEPARTMENTS” with children

    * Dental
    * Human Services
    * Medical
    – Grandchildren
    * health
    * general

    When i am in the grandchildren the children pages disappear. How can i keep the children and grandchildren on the same page?

    the code i am working with:

    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&depth=0&child_of=".$post->post_parent."&echo=0");
    else
    $children = wp_list_pages("title_li=&depth=0&child_of=".$post->ID."&echo=0");
    
    if ($children) { ?>
    
    <ul id="sec_nav">
    <?php echo $children; ?>
    </ul>
    
    <?php } ?>

    thanks for any help.

Viewing 9 replies - 1 through 9 (of 9 total)
  • // Return page tree
    // Template syntax: <?php echo theme_page_tree($post);?>
    function theme_page_tree($this_page) {
    	if( !$this_page->post_parent ) {
    		$pagelist = '<li><a href="'.  get_page_link($this_page->ID) .'">' . $this_page->post_title . '</a>';
    		$children = wp_list_pages('title_li=&child_of='.$this_page->ID.'&echo=0');
    		if( $children ) $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($this_page->ancestors);
    		$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;
    }
    Thread Starter kmaier

    (@kmaier)

    thanks Esmi,

    do i put he function items in the functions.php? if i put that code into my template i get an error.

    http://dev.aihscorp.org/departments/medical/allied-health/

    Yes – add it to functions.php and then use <?php echo theme_page_tree($post);?> within the Loop of any page template.

    Thread Starter kmaier

    (@kmaier)

    put the functions in the functions.php and added <?php echo theme_page_tree($post);?> to my sidebar.php but it comes through as blank now.

    I think it needs to be within your loop.

    Indeed it does – although it would probably work if you just passed it a post or page object too. Just never tried it myself.

    Thread Starter kmaier

    (@kmaier)

    like so? i tried a few different ways but it still came up blank.

    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&depth=0&child_of=".$post->post_parent."&echo=0");
    else
    $children = wp_list_pages("title_li=&depth=0&child_of=".$post->ID."&echo=0");
    
    if ($children) { ?>
    
    <ul id="sec_nav">
    <?php echo theme_page_tree($post); ?>
    </ul>
    
    <?php } ?>

    No – just use <?php echo theme_page_tree($post); ?>.

    Thread Starter kmaier

    (@kmaier)

    i tried that too and blank again. bummer

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘constant struggle’ is closed to new replies.