As it stands your code almost works, but it checks to see if the current page has a parent, which will always be true for both 2nd and 3rd level pages.
WordPress gives us get_ancestors to retrieve an ordered array of ancestors for any hierarchical object type:
get_ancestors( $object_id, $object_type );
So we can use get_ancestors( $post->ID, 'page' )
and count the elements to help us get the depth right for your navigation.
if($post->post_parent) {
$ancestors = get_ancestors( $post->ID, 'page' );
if ( 1 == count( $ancestors ) ) {
echo '<ul>';
wp_list_pages(
array (
'title_li' => '',
'sort_column' => 'menu_order',
'child_of' => $ancestors[0],
'depth' => 1
)
);
echo '</ul>';
}
if ( 2 == count( $ancestors ) ) {
echo '<ul>';
wp_list_pages(
array (
'title_li' => '',
'sort_column' => 'menu_order',
'child_of' => $ancestors[1],
'depth' => 2
)
);
echo '</ul>';
}
}
You could be more clever with the logic, popping the last element off the ancestor array for example, but I’ve kept it verbose for clarity.