<!--
### get_pages() and wp_list_pages() are similar.
### get_pages() -This will returns the ages in memery.
### wp_list_pages() - This function will handle outputting the pages ont the screen for you.
-->
<?php
// If the current page has children this function will return a collection of any all children pages.
// and if the current page doesn't have any children this function won't return anything. It will retun NULL, FALSE or 0.
\!h $testArray = get_pages( array(
'child_of' => get_the_ID()
) );
?>
<!--
### Only display side menu items only if you're currently on a child page
### On a child page, $theParent will returns a number of 0 // TRUE
### Also show if on parent page. $testArray
-->
\!h <?php if( $theParent || $testArray) : ?>
<div class="page-links">
<h2 class="page-links__title">
<a href="<?php echo get_permalink( $theParent ) ?>"><?php echo get_the_title( $theParent ); ?></a>
</h2>
<ul class="min-list">
<?php
$theParent = wp_get_post_parent_id( get_the_ID() );
if( $theParent ) {
$findChildrenOf = $theParent;
}else {
$findChildrenOf = get_the_ID();
}
?>
<?php wp_list_pages(
array(
'title_li' => '', // Get get of 'pages' text output
'child_of' => $findChildrenOf, // link to only children of the page
'sort_column' => 'menu_order' // sort by menu order
)
) ?>
</ul>
</div>
<?php endif; ?>