Fátima Chapri
|
Sunday 11 January 2009 3:51:12 pm
I was searching for a ez random function that could fetch random articles of a folder but didn't find. So I tried the above solution and it worked. I'm just wondering if this is the best solution. Wouldn't it be better to create a function with php code?
{ def $children = array()
$children_count = ''
$rand_number = ''
$last_rand_number = ''
$rand_list = array()
$counter = 0
$counter_end = 4
$object = '' }
{ set $children = fetch( 'content', 'tree', hash( 'parent_node_id', $node.node_id,
'class_filter_type', 'include',
'class_filter_array', array( 'article' )))
$children_count = fetch( 'content', 'tree_count', hash( 'parent_node_id', $node.node_id,
'class_filter_type', 'include',
'class_filter_array', array( 'article' ))) }
{ while ne($counter, $counter_end) }
{ set $rand_number = rand(0, $children_count|sub(1)) }
{if ne($last_rand_number,$rand_number)}
{set $rand_list = $rand_list|append($children[$rand_number])
$counter = inc($counter)
$last_rand_number = $rand_number }
{/if}
{/while}
{foreach $rand_list as $object }
<h4><a href={$object.url_alias|ezurl}>{$object.data_map.title.content|wash}</a></h4>
{/foreach}
{undef}
|
Heath
|
Sunday 11 January 2009 5:45:44 pm
Hello, Try using a shuffle operator. An operator is based on php code.
<i>http://ez.no/developer/contribs/template_plugins/shuffle_4_0
http://ez.no/developer/contribs/template_plugins/extension_shuffle http://ez.no/developer/contribs/template_plugins/random_sort_array_or_fetch_shuffle_operator</i>
Cheers, Heath
Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org
|