Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to: random images
#5
(2014-12-12, 19:24:30)Lars Wrote: Use: DynPages

with this snippet:

<?php
global $args;
$dir = 'data/uploads/'.$args[0];
$files1 = scandir($dir);
$max = count($files1)-1;
$a=get_site_url(false);
$p=explode("/",$a);
$dir="/".$p[3]."/".$dir;
$a=rand(2,$max);
echo "<img src='".$dir."".$files1[$a]."' width='100%'>"
?>

Call it with: {% rndpic slider/3/ %} assumes of course that you name the component "rndpic" and your pic-folder "slider/3/"

You can put your images in a folder. That's all.

If you need a shadowbox you can add this very easy.

The snippets read any picture in a given folder, put them in an array and select a random pic for display.
It does not work entirely. the image url shows up like this: http://data/uploads/raimg1/wm12.jpg (folder name of first group is raimg1)
So basicly the site url is not present in the url.
Reply


Messages In This Thread
How to: random images - by datiswous - 2014-12-11, 21:26:57
RE: How to: random images - by Lars - 2014-12-12, 19:24:30
RE: How to: random images - by datiswous - 2014-12-12, 22:57:18
RE: How to: random images - by lesh - 2014-12-13, 01:57:44
RE: How to: random images - by datiswous - 2014-12-12, 19:52:57
RE: How to: random images - by Lars - 2014-12-12, 20:29:17
RE: How to: random images - by shawn_a - 2014-12-13, 02:01:07
RE: How to: random images - by datiswous - 2014-12-15, 04:37:44
RE: How to: random images - by Lars - 2014-12-13, 02:44:46
RE: How to: random images - by shawn_a - 2014-12-15, 04:42:28
RE: How to: random images - by datiswous - 2014-12-15, 06:33:23



Users browsing this thread: 1 Guest(s)