Skip to content

Instantly share code, notes, and snippets.

@dubrod
Created November 30, 2018 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubrod/3d64b69f945bc10743a51df63dfebb4a to your computer and use it in GitHub Desktop.
Save dubrod/3d64b69f945bc10743a51df63dfebb4a to your computer and use it in GitHub Desktop.
simple ultimate parent title
<?php
//4 levels deep
$title = '';
//first level parent
$parentId = $modx->resource->get('parent');
if($parentId == 0){
$title = $modx->parseChunk('interior-title', array('title' => $modx->resource->get('pagetitle') ));
return $title;
} else {
//its not the root, go again
$parentObj = $modx->getObject('modResource', $parentId);
$gId = $parentObj->get('parent');
}
if($gId == 0){
$title = $modx->parseChunk('interior-title', array('title' => $parentObj->get('pagetitle') ));
return $title;
} else {
//its not the root, go again
$gObj = $modx->getObject('modResource', $gId);
$ggId = $gObj->get('parent');
}
if($ggId == 0){
$title = $modx->parseChunk('interior-title', array('title' => $gObj->get('pagetitle') ));
return $title;
} else {
//its not the root, go again
$ggObj = $modx->getObject('modResource', $ggId);
$gggId = $ggObj->get('parent');
}
if($gggId == 0){
$title = $modx->parseChunk('interior-title', array('title' => $ggObj->get('pagetitle') ));
return $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment