Checking current pageID against parent page ID down sitemap tree

Permalink
Hi,

I'm trying to hard code a pagelist that shows all pages with page type 'News'. I've created a custom attribute select list for my client to choose the type of news it is i.e.

- Production
- Stage
- Technical

However, I need to show only the 'Technical' news in the 'Technical section whether that is on the Technical page itself or several levels down i.e.

- Technical
- - Subpage 1
- - - Sub subpage 1
- - - Sub subpage 2
- - Subpage 2
etc.

The same with Stage and Production news. My idea was to hardcode in a pagelist block with a pagelist, and then write some logic in a pagelist custom template that uses the parent page ID for the current page.

The logic would be something like this:

if($parentpage == 'Technical') {
  echo $technicalNewsOnly;
}
if($parentpage == 'Production') {
  echo $productionNewsOnly;
}
if($parentpage == 'Stage') {
  echo $stageNewsOnly;
}


Does anyone know how I'd do this? Not sure how to grab the parent page ID for a current page if it's far down the sitemap tree.

Thanks

osu

osu
 
beebs93 replied on at Permalink Reply
beebs93
I wrote a class that would generate an unordered list of all the child pages under a particular page. Here's a snippet that includes a recursive method that may help:
private function getChildHtml($objPage){
      $arrAllPageIDs = array();
      $strHtml = NULL;
      if($this->validPageObj($objPage)){
         // Get ALL child page IDs
         $arrAllPageIDs = $objPage->getCollectionChildrenArray($intOneLevel = 1);
         $strHtml = "\n<ul class='childList'>";
         foreach($arrAllPageIDs as $intPageID){
            $obj = Page::getByID($intPageID);
            // If a valid page object
            if($this->validPageObj($obj)){            
               $strLink = $obj->cPath;
               $strTitle = $obj->getCollectionName();            
               $strHtml .= '<li class="childItem"><a class="childLink" href="' . $strLink . '" title="' . $strTitle . '">' . $strTitle . '</a>';
               // If page has any children


The "validPageObj" method simply checks that the argument is a valid Page object and is not empty/has no errors.

So in this example, you would get a Page object by the ID of each of those parent pages you mentioned and feed it to this method.