Created
July 25, 2013 20:36
-
-
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`]]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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