Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dubrod
Created November 30, 2018 00:40
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/a0ee8e1dc2941e21c5f0b87064efe919 to your computer and use it in GitHub Desktop.
Save dubrod/a0ee8e1dc2941e21c5f0b87064efe919 to your computer and use it in GitHub Desktop.
collection of modx parent snippets
GetParentAlias
$output = '';
/* Get the current resource's 'parent' field */
$parentId = $modx->resource->get('parent');
/* Get the parent object */
$parentObj = $modx->getObject('modResource', $parentId);
/* If we have the parent,
get and return the alias */
if ($parentObj) {
$output = $parentObj->get('alias');
}
return $output;
-----
GetParentPagetitle
$output = '';
/* Get the current resource's 'parent' field */
$parentId = $modx->resource->get('parent');
/* Get the parent object */
$parentObj = $modx->getObject('modResource', $parentId);
/* If we have the parent,
get and return the pagetitle */
if ($parentObj) {
$output = $parentObj->get('pagetitle');
}
return $output;
-----
<?php
$output = '';
$id = $modx->getOption('id', $scriptProperties);
$idObj = $modx->getObject('modResource', $id);
$parentId = $idObj->get('parent');
$parentObj = $modx->getObject('modResource', $parentId);
$gId = $parentObj->get('parent');
$gObj = $modx->getObject('modResource', $gId);
if ($gObj) {$output = $gObj->get('pagetitle');}
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment