Sometimes in WordPress you need to find the name or ID of the top-level page or post. This is actually pretty easy.
$parents = array_reverse(get_post_ancestors($post->ID));
$firstparent = get_page($parents[0]);
echo $firstparent->post_name;
echo $firstparent->ID;
$firstparent = get_page($parents[0]);
echo $firstparent->post_name;
echo $firstparent->ID;
Hope this helps.
