Define how many random images you want, where you want

Argos

Are you referring to http://www.websitebakers.com/pages/modules/image-galleries/random-image.php ? I'm not sure I understand the difference between that one and your code... Can you explain?

Also, is there a difference with the droplets http://www.websitebakers.com/pages/droplets/official-library/images/randomorderimages.php and http://www.websitebakers.com/pages/droplets/official-library/images/random-images.php ?

I'm getting a bit confused by all these random image solutions  :roll:
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

pieterb

Hi everybody,

I checked out the snippet for a random image and used it, but i wasn't able to display an array of random images with it. So a friend of mine helped me out and we made the following code:

<?php
$imgs 
scandir('../media/random');
foreach (
$imgs as $k => $img) {
  if (!
stripos($img".jpg")) {
    unset(
$imgs[$k]);
  }
}
$imgs array_rand(array_flip(array_values($imgs)), 11);
foreach (
$imgs as $img) {
  echo 
"<img src=\"../media/random/{$img}\" title=\""substr($img0, -4). "\" width=\"75\" height=\"100\" />";
}
?>


Using this, you can define the folder (you will have to do this twice in the code, sorry), the number of images in your array (in this case 11) and set the width and height of all the images. It doesn't matter what the name of the files is; it just reads in the entire folder. As long as it's jpg's you're using, you're fine. The title attribute is the name of the file without the .jpg extension.

Off course you can create additional possibilities with this, for example creating a caption per image that uses the same information as the title attribute, but I didn't need it.

I hope someone else will find it useful too.