It depends on whether they are all immediate children (e.g., no grandchildren).
If there are no grandchildren, this will be significantly faster:
$docId = $modx->resource->get('id');
$tpl = $modx->getOption('tpl',$scriptProperties,'');
if (!$tpl) {
return 'No template given.';
}
$c = $modx->newQuery('modResource');
$c->where(array('parent' => $docId));
$c->sortby('publishedon', 'DESC');
$docs = $modx->getCollection('modResource', $c);
$output = '<h2>[[*pagetitle]]</h2><ul>';
foreach ($docs as $doc) {
$fields = $doc->toArray();
$output .= $modx->getChunk($tpl, $fields);
}
$output .= '</ul>';
return $output;
If there are grandchildren, you can do it like this:
$c = $modx->newQuery('modResource');
$c->sortby('publishedon', 'DESC');
$docs = $modx->resource->getMany('Children', $c);