Last Updated: June 27, 2020 | Reading Time: < 1 minute
There are many
function sb_child_page_menu( $current_parent ) {
// Display Subpages on the parent and list subpages of the current parent if on the child page
if(wp_get_post_parent_id($current_parent)) {
$parent_ID = wp_get_post_parent_id( $current_parent );
} else {
$parent_ID = $current_parent;
}
// Get the Childpages / Subpages using get_children function
$arg = array(
'post_parent' => $parent_ID,
);
$childrens = get_children( $arg );
if( !empty($childrens) ) {
echo '<div class="sub-page">';
foreach ( $childrens as $children ) {
echo '<a href="'.get_permalink($children->ID).'">'.$children->post_title.'</a>';
}
echo '</div>';
}
}
Call the function within the template file:
sb_child_page_menu( get_the_ID() );