WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.

Donate with PayPal buttonSpenden mit dem PayPal-Button

  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Define how many random images you want, where you want
  • Print
Pages: [1]   Go Down

Author Topic: Define how many random images you want, where you want  (Read 5477 times)

Offline pieterb

  • Posts: 46
  • Gender: Male
Define how many random images you want, where you want
« on: March 22, 2009, 09:20:56 AM »
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:

Code: [Select]
<?php
$imgs 
= scandir(&#39;../media/random&#39;);
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($img, 0, -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.
Logged

Argos

  • Guest
Re: Define how many random images you want, where you want
« Reply #1 on: March 26, 2009, 11:13:06 AM »
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:
Logged

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Define how many random images you want, where you want
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2