[pmwiki-users] show random image

Hans design5 at softflow.co.uk
Thu Nov 22 06:12:46 CST 2007


Thursday, November 22, 2007, 11:48:53 AM, Petko Yotov wrote:

> One of them is Thumblist :
>   (:thumblist shuffle=1:)

> A demonstration can be seen here: 
>   http://galleries.accent.bg/Thumblist/Shuffle

Thank you! But maybe I don't need to install a whole gallery script
for the task of a rotating image on a home page.

I just come up with this simple solution, based on the rand function:

# Create a  markup expression {(random xx zz)}
$MarkupExpr['random'] = 'MakeRandomNumber( $args[0], $args[1])';
function MakeRandomNumber( $n1, $n2) {
        $l = strlen($n2);
        $rn = rand($n1, $n2);
        return sprintf("%0{$l}d",$rn);
}

This returns a formatted random number, with a number of digits
according to the second argument:
so {(random 1 30)} will return a random number between 01 and 30
(inclusive). Note it starts at 01, not 1. I want the leading zeros so
I can use it in standard image file names for the page markup:

   Attach:image_{(random 1 30)}.jpg

and it will display an image from a collection from
image_01.jpg to image_30.jpg

BTW: anyone knows why the {(rand)} markup expression does not work?
see http://www.pmwiki.org/wiki/Cookbook/MarkupExpressions-Sandbox


  ~Hans




More information about the pmwiki-users mailing list