Wednesday 19 October 2011

How to display parent page title in sub pages?


WordPress will have an option to create sub page for a page. We may have any number of sub pages for a parent page .Suppose if we created pages in this way like parent and child relation and if we want to display the parent page in all the sub pages just follow these steps.

    wp_title('');  function is used to display the title of current page.
<?php 
if($post->post_parent)
{
$pagetitle=get_the_title($post->post_parent);
echo $pagetitle;
}
?>


Place the above code where you want to display the title of the parent page. In the above code first it will check that the page has a parent page or not. If it is true then it will display the title of the page.

The above code will be very easy for the WordPress advanced developers. I am working on WordPress from so many days but I did observe this $post->post_parent. There may be someone like me that’s why I am sharing this.

Hope it is useful.

No comments:

Post a Comment