Skip to content

Instantly share code, notes, and snippets.

@besimhu
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save besimhu/be07c2c145d867c0c55e to your computer and use it in GitHub Desktop.
Save besimhu/be07c2c145d867c0c55e to your computer and use it in GitHub Desktop.
Show child pages of parent, or if viewing child page, it will get all pages associated with parent.
<aside>
<nav class="page-sub-navigation">
<?php
// get child pages from post parent, otherwise
// get child pages from the current page being viewed, in most cases the parent
if ($post->post_parent) {
$page_list = wp_list_pages( 'title_li=&display=0&child_of='.$post->post_parent.'&echo=0' );
} else {
$page_list = wp_list_pages( 'title_li=&display=0&child_of='.$post->ID.'&echo=0' );
}
// if child pages exist, load them in otherwise
if ($page_list):
echo '<ul>';
echo $page_list;
echo '</ul>';
endif;
?>
</nav>
</aside>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment