Skip to content

Instantly share code, notes, and snippets.

@exside
Created March 2, 2013 21:20
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 exside/5073343 to your computer and use it in GitHub Desktop.
Save exside/5073343 to your computer and use it in GitHub Desktop.
<?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 <bert@oostdesign.nl>
*/
$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