Put this in your functions.php
:
function my_title() {
if (is_home())
echo 'News';
else {
global $post;
if ($post->post_parent)
echo get_post($post->post_parent)->post_title;
else echo $post->post_title;
}
} // function my_title
and then use <?php my_title(); ?>
anywhere you want.
The above code prints News on the home page, for child posts the name of their respective parent, and the post title otherwise.
If you want to do this for pages only (no other post types), then use this:
function my_title() {
if (is_home())
echo 'News';
else {
global $post;
if ('page' === $post->post_type && $post->post_parent)
echo get_post($post->post_parent)->post_title;
else echo $post->post_title;
}
} // function my_title