Last active
September 26, 2016 13:26
-
-
Save nickberens360/8152388 to your computer and use it in GitHub Desktop.
wordpress: List parent and child pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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