This question has been answered by opengeek. See the first response.
&sortby=`RAND()`
&sortby=`FIELD(modResource.id, 4,7,2,5,1 )`
<?php
//[[daylidoc? &parent=`13`&chunkname=`daylidoc`&excludedocs=`18`]]
//[[daylidoc? &parent=`13`&chunkname=`daylidoc`&mode=`week`&dayoffset=`5`]]
$chunkname = isset ($chunkname)?$chunkname:'daylidoc';
$mode = isset ($mode)?$mode:'day';//day,week,month
$dayoffset = isset ($dayoffset)?$dayoffset:1;
if ( isset ($parent))
{
$table = $modx->getFullTablename('site_htmlsnippets');
$rs = $modx->db->select('*', $table, 'name="'.$chunkname.'"');
$chunk = $modx->db->getRow($rs);
date_default_timezone_set('Europe/Berlin');
switch($mode)
{
case 'month':
$dateformat = '%m.%Y';
$date = @strftime($dateformat);
break;
case 'week':
$timestamp=time();
$ts_dow = ($w = date("w", $timestamp))?$w:7;
$ts_day = strftime("%d", $timestamp);
$ts_month = strftime("%m", $timestamp);
$ts_year = strftime("%Y", $timestamp);
$timestampweekstart = mktime(0, 0, 0, $ts_month, $ts_day-$ts_dow+$dayoffset, $ts_year);
$dateformat = '%d.%m.%Y';
$date = 'week starts at '.@strftime($dateformat,$timestampweekstart);
break;
case 'day':
default:
$dateformat = '%d.%m.%Y';
$date = @strftime($dateformat);
}
$fields['description'] = 'randomID for '.$date;
$randomDocID = $chunk['snippet'];
if (is_array($chunk)){
$excludedocs=isset($excludedocs)?explode(',',$excludedocs):array();
$excludedocs[]=$randomDocID;
$excludedocs=implode(',',$excludedocs);
}
$excludedocs=isset($excludedocs)?' AND id not IN ('.$excludedocs.')':'';
if (is_array($chunk))
{
if ($fields['description'] !== $chunk['description'])
{
$table2 = $modx->getFullTablename('site_content');
$rs = $modx->db->select('id,rand() as random', $table2, 'parent='.$parent.$excludedocs, 'random', '1');
$randomdoc = $modx->db->getRow($rs);
if (is_array($randomdoc))
{
$fields['snippet'] = $randomDocID = $randomdoc['id'];
$modx->db->update($fields, $table, 'name="'.$chunkname.'"');
}
}
}
else
{
$table2 = $modx->getFullTablename('site_content');
$rs = $modx->db->select('id,rand() as random', $table2, 'parent='.$parent.$excludedocs, 'random', '1');
$randomdoc = $modx->db->getRow($rs);
if (is_array($randomdoc))
{
$fields['snippet'] = $randomDocID = $randomdoc['id'];
$fields['name'] = $chunkname;
$modx->db->insert($fields, $table);
}
}
}
return $randomDocID;
?>
Ideally, there'd be an "&cache" parameter that let you set a number of seconds that the thing would be cached, so it could refresh every day.Just wrap getResources with the getCache Snippet. This should support everything you need to set cache items which expire at specific times or intervals from any Snippet that returns it's output.
The only work-around I can think of would either be to cron something in the command line that cleared the cache programmatically on a daily basis, or write a snippet that relied on modular division ...
If you're just grabbing on post, you probably don't even need getResources...