Parent section name (w/ multi-tier)

Permalink 1 user found helpful
I looked around the forums and found the way to embed the section name within a template is to use
<?php $page = Page::getByID($c->getCollectionParentID()); print $page->getCollectionName();?>
So even if your on a subpage of a section, the main section name is still displayed. My issue is, if someone goes three levels deep, then the second pages name is displayed as the section name. Is there a way to prevent that? So basically I always want to show the top level parent name, no matter how many levels deep you are. Thanks.

hursey013
 
netnerd85 replied on at Permalink Reply
I'm also looking for a solution to this problem, anyone? there must be a way?
dg1 replied on at Permalink Reply
You could set up a loop where you navigate up the tree of parents until you find one where there is some indicator that you have reached the top page of the section (e.g. a page attribute has been set).
mdzoidberg replied on at Permalink Reply
mdzoidberg
Here is the answer:

<?php 
      global $c;
      $nh = Loader::helper('navigation');
      $cobj = $nh->getTrailToCollection($c);
      ?>
            <?php
         $rcobj = array_reverse($cobj);
         if(is_object($rcobj[1]))
         {
            $pID  = $rcobj[1]->getCollectionID();
            $page = Page::getByID($pID);  
            $title= $page->getCollectionName();
         }else{
            $title= $c->getCollectionName();
         }


Taken from this post,http://www.concrete5.org/community/forums/customizing_c5/nested-pag...

Cheers.