Skip to content

Instantly share code, notes, and snippets.

@nickberens360
Last active September 26, 2016 13:26
Show Gist options
  • Save nickberens360/8152388 to your computer and use it in GitHub Desktop.
Save nickberens360/8152388 to your computer and use it in GitHub Desktop.
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 } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment