Get top level Parent Name (under Home)

Permalink
Hi,

I need to get the Top level Parent Name (under Home) and add it as a class. It always needs to display the level under Home regardless of how many levels deep the page is.

Here's what I have so far which is just the Parent Page.

$parent = Page::getByID($c->getCollectionParentID()); echo $parent->getCollectionName();


Thanks

sarah3585
 
nebuleu replied on at Permalink Reply
nebuleu
You can use the very useful getTrailToCollection() from the Navigation helper.
http://www.concrete5.org/documentation/developers/helpers/navigatio...

Something like this should do what you want :

$nh = Loader::helper('navigation');
$c = Page::getCurrentPage();
// get all parents pages in breadcrumb order
$collectionTrail = array_reverse($nh->getTrailToCollection($c));
// add current page to array
array_push($collectionTrail, $c);
if (array_key_exists(1, $collectionTrail)) {
   echo $collectionTrail[1]->getCollectionName();
}