public
Created

  • Download Gist
multi.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?php
// Check if a page has any parent pages
if ($post->ancestors) {
// How many ancestors does this page have? Then subtract by 1 to adjust for top level
$n = count($post->ancestors);
$n = $n - 1;
// Get the page's children, if it has any
$pages = get_pages();
$page_children = get_page_children($post->ID, $pages);
// Checks if a page has children
if (!empty($page_children)) {
$children = wp_list_pages("title_li=&child_of=". $post->ancestors[$n] ."&echo=0&sort_column=menu_order&depth=" . ($n + 2));
} else { // If the page doesn't have children
$children = wp_list_pages("title_li=&child_of=". $post->ancestors[$n] ."&echo=0&sort_column=menu_order&depth=" . ($n + 1));
}
} else {
$children = wp_list_pages("title_li=&child_of=". $post->ID ."&echo=0&sort_column=menu_order&depth=1");
}
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.