Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Random section loop

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
bughy84
Smarty n00b


Joined: 18 Sep 2013
Posts: 1

PostPosted: Wed Sep 18, 2013 1:29 pm    Post subject: Random section loop Reply with quote

Hi,

i have this code:

Code:
{section name="id_firm" loop=$a_firm_display max=5}
<a href="{$smarty.const.HOST}{$a_firm_display[id_firm].url_rewriting}"><img src="{$a_firm_display[id_firm].firm_logo}" /></a>
{/section}


I can't figure how to make them show random. That code display 50 images with links. But i need to show only 5 (i used max=5) and i need to be random (on each refresh of the page to show 5 random images)
Can someone help me please?

Thx in advance
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4507
Location: Hamburg / Germany

PostPosted: Wed Sep 18, 2013 4:31 pm    Post subject: Reply with quote

See PHP function array_rand

Code:
{foreach array_rand($a_firm_display,5) as $i}
<a href="{$smarty.const.HOST}{$a_firm_display[$i].url_rewriting}"><img src="{$a_firm_display[$i].firm_logo}" /></a>
{/foreach}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP