PHP – WordPress – Get Current Page Parent

The given PHP example helps you to returns the page object of the parent of the current page. 

Code Example:
<?php
function get_parent_page() {
	global $post;
    $topParent = $post;
    while ($topParent->post_parent) {
    	$topParent = $topParent->post_parent;
    }
    return get_page($topParent);
}
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *