Nested Pages getCollectionName of First Parent

I'm trying to display the name of the first parent of a page as a sub-heading. Obviously, this can be done using the getCollectionParentID function and then getting the collection name by using that ID with the Page element. The problem I'm running in to is that on a third-level nested element, the ID returned by getCollectionParentID is that of the direct parent and not the first parent.

How do I find the name of the first-level parent, which is sometimes a grandparent or great-grandparent?

I think I'm trying to do the same thing: always display the ultimate parent one down from the home page, no matter where you are in the tree - is that what your code does?

I've duplicated the normal atonav template (which is working great) and am now trying to integrate your code but keep getting "Catchable fatal error: Object of class Page could not be converted to string" - then gives the line number of the echo statement.

I suspect it's because I don't fully understand how to echo stuff out properly so am hoping it's a simple fix someone could help with.

Here's my template to the point I'm trying to echo the ultimate parent:

Ben, your page variable is not existing outside the scope of the if statement so no wonder you get an error. In PHP variables are scoped. So the just declaring the $page before the if statement should work.

This is the start of my autonav template which is just a straight duplication of the default autonav template (the one that creates a nested menu structure) with my ul class added as a wrapper at the top.

<!-- sub navigation -->
<ul class="s-nav">
<?phpdefined('C5_EXECUTE') or die("Access Denied.");$aBlocks=$controller->generateNav();$c= Page::getCurrentPage();$containsPages=false;$nh= Loader::helper('navigation');// -- START Always display ultimate parent at top of NAV --// If not on the home page if($c->cID>1){$nh= Loader::helper('navigation');$arrTrail=array_reverse($nh->getTrailToCollection($c));$objHomePage=$arrTrail[0];// Home page object;// If we're on a top-level page then our $arrTrail array will only have the home page object// so we test to see if its Page object exists

<!-- sub navigation -->
<ul class="s-nav">
<?phpdefined('C5_EXECUTE') or die("Access Denied.");$aBlocks=$controller->generateNav();$c= Page::getCurrentPage();$containsPages=false;$nh= Loader::helper('navigation');// -- START Always display ultimate parent at top of NAV --// If not on the home page if($c->cID>1){$nh= Loader::helper('navigation');$arrTrail=array_reverse($nh->getTrailToCollection($c));$objHomePage=$arrTrail[0];// Home page object;// If we're on a top-level page then our $arrTrail array will only have the home page object// so we test to see if its Page object exists$objTopPage=is_object($arrTrail[1])&&$arrTrail[1] instanceof Page &&!$arrTrail[1]->error ? $arrTrail[1]:$c;// If we have a valid top page Page object we retrieve $title=$objTopPage->getCollectionName();$url=$nh->getLinkToCollection($objTopPage);// print parentecho'<li><a class="current" href="'.$url.'"'.'>'.$title.'</a>'.'</li>';}// -- END Always display ultimate parent at top of NAV --// -- START default autonav temlate --