Randomize your images with Smarty

If you want to show random image on every page load you could use this short smarty code in your Template.

{assign var='header_images' value='uploads/relative/path/to/images/*.*'|glob}
{capture assign='equation'}rand(0,{$header_images|@count}-1){/capture}
{math equation=$equation assign='imgnumber'}
{if !empty($header_images)}
<img src="{$header_images.$imgnumber}" alt="{$sitename}" width="400" height="200" />
{/if}

Comments