Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2012, 09:10:15 AM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155482 Posts in 21708 Topics by 7734 Members
Latest Member: adrielkhollis4
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Define how many random images you want, where you want  (Read 1115 times)
pieterb

Offline Offline

Posts: 46



« 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:
<?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.
Logged
Argos
Moderator
**
Offline Offline

Posts: 2156


WWW
« 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  rolleyes
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!