I agree with Mark H.
It sounds like you are using the resource’s template as the search criterion. If the ID of the screenshot template is 12, something like this (untested) would get and display links to the ten most recent screenshots in a single query:
<?php
/* ShowScreenShots */
$c->where(array(
'published'=>'1',
'deleted'=>'0'.
'template'=>'12',
));
$c->sortby('createdon', 'ASC');
$c->limit(10);
$docs = $modx>getCollection('modResource', $c);
foreach ($docs as $doc) {
$output .= '<p><a href="' . $doc->get('pagetitle'). '">' . '[[~' . $doc->get('id') .']]</a></p>';
}
return $output;
To make it more generic, you could send the template ID in the tag as a property:
[[!Show? &usesTemplate=`12`]]
and replace
with
'template'=>$scriptProperties['usesTemplate'],
To make it truly the "MODX way," you’d put the HTML in a chunk called ShowChunk with placeholders
<p><a href="[[+show.pagetitle]]"> [[~[[+show.id]]]]</a></p>
Then in the loop in your snippet:
$fields = array(
'show.pagetitle'=>$doc->get('pagetitle'),
'show.id'=>$doc->get('id');
}
$output .= $modx->getChunk('ShowChunk, $fields);