Here is how I am doing random headers. I have a container for the "header" documents. It is a simple template with one TV for the photo. I use the content are for a small caption. Then I have a snippet that use those documents as the source for my headers in my main pages. When I need a new header, I just create a new document in the Banner directory and add the photo to the TV, and it goes into the rotation. Another advantage is that you can schedule those documents for publishing as well. I hacked a snippet from sotwell and made it work. I had tried different things until I git it to work and never changed it. It could use some cleaning up...
In my main template:
[!ShowRandom? &startDoc=`8` &numItems=`1`!]
My "Banner" chunk:
<div id="value-statement">
<div id="value-padding">
<div id="centered">
<p>[+bio+]</p>
</div>
</div>
</div>
<div id="photo-top">
[+bannerphoto+]
</div>
My modified snippet (I made changes to suit my needs, some information is hardcoded):
<?php
// snippet ShowRandom
// display content from random documents
// sottwell 01-2006
// arguments:
// &startDoc - ID of folder to select items from
// &numItems - number of random items to display
// &tpl = chunk name for item display template
$startDoc = isset($startDoc) ? $startDoc : $modx->documentIdentifier;
$numItems = isset($numItems) ? $numItems : 1;
$tpl = isset($tpl) ? $modx->getChunk($tpl) : '
<div class="randItem">
[+content+]
</div>
';
$resource = $modx->getActiveChildren($startDoc, 'createdon', 'DESC', $fields='id, pagetitle, description, introtext, content, createdon, createdby, hidemenu');
$limit = count($resource);
if(!function_exists(randArray)) {
function randArray($size, $min, $max) {
if ($size > $max)
$size = $max;
$v = array();
while ( count($v) < $size ) {
do {
$n = rand( $min, $max );
} while ( array_search($n, $v) !== false);
$v[] = $n;
}
return $v;
}
}
$list = randArray($numItems,0,$limit-1);
$items = '';
foreach($list as $item) {
$items .= str_replace('[+bio+]',$resource[$item]['content'],$tpl);
$tvoutput = $modx->getTemplateVarOutput(array('photo'), $resource[$item]['id']);
}
$chunkArr = array(
'bio' => $resource[$item]['content'],
'bannerphoto' => $tvoutput['photo']
);
$output .= $modx->parseChunk('Banner', $chunkArr, '[+', '+]');
return $output;
// return $items;
?>