nickberens360
12/27/2013 - 8:42 PM

wordpress: List parent and child pages

wordpress: List parent and child pages

<?php 
global $post; // Setup the global variable $post
if ( is_page() && $post->post_parent ) // Make sure we are on a page and that the page is a parent
	$kiddies = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
else
	$kiddies = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
 
if ( $kiddies ) {
	echo '<ul class="secondary">';
		echo $kiddies;
	echo '</ul>';
}
?>

//shows full family structure
<?php if(!$post->post_parent){
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
}else{
    if($post->ancestors)
    {
        $ancestors = end($post->ancestors);
        $children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
    }
}
if ($children) {
    ?>
    <ul class="sideNav__list bulletLess"> <?php echo $children; ?></ul>
<?php } ?>