Skip to content

Instantly share code, notes, and snippets.

@miduku
Created July 25, 2013 20:36
Show Gist options
  • Save miduku/6083517 to your computer and use it in GitHub Desktop.
Save miduku/6083517 to your computer and use it in GitHub Desktop.
for MODX REVO traverse up the amount of levels you want from the current resource and get its id. @example: [[GrandParent? &levels=`2`]]
<?php
/**
* [[GrandParent]]
*
* traverse up the amount of levels you want from the current resource and get its id.
* @example:
* [[GrandParent? &levels=`2`]]
*
* inspired by http://www.sepiariver.ca/blog/modx-web/modx-quick-tip-get-id-of-grandparent
*/
$id = $modx->resource->get('id');
$parents = $modx->getParentIds($id, $levels);
$grandParent = $parents[$levels-1];
return $grandParent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment