[pmwiki-users] automatic Trail with random back & next

Hans design5 at softflow.co.uk
Tue Jul 22 04:03:30 CDT 2008

Monday, July 21, 2008, 10:51:39 PM, Stéphane Heckel wrote:

> tested with beta-65, markup in both page's body and includes, ...
> it works ok for me.


Here is another expression, which is more general.
It selects at random one item from a list of items supplied,
by default from a CSV list, but the item separator can be choosen.
Combine this with (plist) or (pagelist) markuop expression and you
can construct random links like in the (rndpage) expression.
(plist0 lets you use nice exclusive and inclusive wildcard pagename
Or you can use it for entirely different things, where you wish to
have  arandom pick of something.
Again this expression function keeps track of items already choosen
before, so it will not display doubles.

//add markup expression {(random item1,item2,item3,item4 sep=SEPARATOR)}
$MarkupExpr['random'] = 'MXRandomItem($pagename, $args[0],$argp)';
function MXRandomItem($pagename, $list, $args) {
        global $RandomItemsUsed; echo $args['sep'];
        $sep = (isset($args['sep'])) ? $args['sep'] : ',';
        $sep = str_replace('\n',"\n",$sep);
        $list = explode($sep,$list);
        foreach($list as $i => $item)
                if (in_array($item,(array)$RandomItemsUsed) || $item=='') 
        echo "<pre>\$list "; print_r($list); echo "</pre>";             
        $i = rand(0,count($list)-1);
        $RandomItemsUsed[] = $list[$i];
        return $list[$i];       

a link markup may look something like this:

[[{(random (plist -Recent* -Group*))}|+]]


More information about the pmwiki-users mailing list