Skip to content

Instantly share code, notes, and snippets.

@dubrod dubrod/modx-up-title
Created Nov 30, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.