I want to pull one random item and display it on a page.
Using this fails:
Code: Select all
{cms_module module='Cataloger' action='random' sub_template='Vaughn-Category-1' alias='/' count='1'}Example: http://www.vaughnsphotoart.com/index.ph ... om-count-1
Using this works:
Code: Select all
{cms_module module='Cataloger' action='random' sub_template='Vaughn-Category-1' alias='/' count='2'}Example: http://www.vaughnsphotoart.com/index.ph ... om-count-2
Here is the code of /modules/Cataloger/action.random.php ... it's short so I'm pasting the whole thing. You can see it has special code for handling when count=1 , but I'm not a programmer and can't diagnose it.
action.recent.php works fine, for what it's worth.
Code: Select all
<?php
if (!isset($gCms)) exit;
foreach ($params as $key=>$val)
{
$this->smarty->assign($key, $params[$key]);
}
if (! isset($params['recurse']))
{
$params['recurse'] = 'items_all';
}
list($curPage,$categoryItems) = $this->getCatalogItemsList($params);
$count = min(count($categoryItems),$params['count']);
$thisUrl = $_SERVER['REQUEST_URI'];
$thisUrl = preg_replace('/(\?)*(\&)*start=\d+/','',$thisUrl);
if ($count == 1)
{
$categoryItems = $categoryItems[array_rand($categoryItems,1)];
$this->smarty->assign('items',$categoryItems);
}
else if ($count == 0)
{
$this->smarty->assign('items',array());
}
else
{
$categoryItemKeys = array_rand($categoryItems, $count);
$catTmp = array();
foreach($categoryItemKeys as $thisKey)
{
array_push($catTmp,$categoryItems[$thisKey]);
}
$this->smarty->assign('items',$catTmp);
}
echo $this->ProcessTemplateFromDatabase($this->getTemplateFromAlias($params['sub_template']));
?>

