Find ID of Top-Most Parent Page. This will find what the ID is of the top-most parent Page, in a nested child page. For example, this page you are literally looking at is nested under. $parent will be the correct ID. For example, for use with wp_list_pages.
<?php
if ($post->post_parent) {
$ancestors=get_post_ancestors($post->ID);
$root=count($ancestors)-1;
$parent = $ancestors[$root];
} else {
$parent = $post->ID;
}
?>