Created
March 2, 2013 21:20
-
-
Save exside/5073343 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* FirstChildId | |
* Gets the first child id of the given id. Works as output filter. | |
* Example use: [[*id:FirstChildId]] | |
* | |
* @autor Bert Oost at OostDesign.nl <[email protected]> | |
*/ | |
$id = (!empty($input)) ? $input : false; | |
if(!empty($id)) { $id = $modx->getOption('id', $scriptProperties, $modx->resource->get('id')); } | |
// select the first child | |
$c = $modx->newQuery('modResource'); | |
$c->select('`modResource`.`id`'); | |
$c->where(array( | |
'parent' => $id, | |
'published' => true | |
)); | |
$c->sortby('menuindex', 'ASC'); | |
$c->limit(1); | |
$child = $modx->getObject('modResource', $c); | |
if(!empty($child) && $child instanceof modResource) { | |
return $child->get('id'); | |
} | |
return $id; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment