listing random nodes

Author Message

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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 06:25:48
Script start
Timing: Jan 19 2025 06:25:48
Module start 'layout'
Timing: Jan 19 2025 06:25:48
Module start 'content'
Timing: Jan 19 2025 06:25:48
Module end 'content'
Timing: Jan 19 2025 06:25:48
Script end

Main resources:

Total runtime0.0130 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0048 589.0547152.6094
Module start 'layout' 0.00480.0027 741.664139.4141
Module start 'content' 0.00750.0037 781.078189.4297
Module end 'content' 0.01130.0017 870.507834.3047
Script end 0.0129  904.8125 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002217.0807140.0002
Check MTime0.00107.6520140.0001
Mysql Total
Database connection0.00075.487810.0007
Mysqli_queries0.002317.624530.0008
Looping result0.00000.091910.0000
Template Total0.001410.610.0014
Template load0.00075.046810.0007
Template processing0.00075.531910.0007
Override
Cache load0.00053.522010.0005
General
dbfile0.00032.259880.0000
String conversion0.00000.045940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs