mattgdavies
Member
Posted 3 years ago #
Hi there,
I wonder if anyone can help a novice like me! I've searched and searched but can't seem to get anything to work.
Ok - I need to get the page title of the root of a pages ancestor.
So for example if the site map looked like this:
I'd like it so that wither we were in the Child page,Parent page or GrandParent Page, what would display was the "Great Grandparent" title.
The reason for this is because the site is to work in sections.
Any help would be much appreicated
kapiljain.in
Member
Posted 3 years ago #
This seems to work also:
<?php
//get root ancestor for page 234
$a=get_post_ancestors(234);
$root=count($a)-1;
echo "root page id " . $a[$root];
?>
kapiljain.in
Member
Posted 3 years ago #
Thanks MichaelH,
I checked mentioned code, it works fine for the sub level pages but returns nothing for top level pages.
mkormendy
Member
Posted 2 years ago #
In that case .. top level pages would be retrieved from their top level wp_title function. You have to then create an if/else statement that will:
- check whether the page is a sub page
- if it is a sub-page, find the parent(root page)
- if it is a top level page, get the wp_title
Done.