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.9 is now available!


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.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Droplet: random image(s) from a media-dir with lightbox popup
  • Print
Pages: [1]   Go Down

Author Topic: Droplet: random image(s) from a media-dir with lightbox popup  (Read 8298 times)

Argos

  • Guest
Droplet: random image(s) from a media-dir with lightbox popup
« on: November 02, 2011, 01:27:06 PM »
I wanted to have a droplet that shows a certain number of random images from a media-dir, and showed large version in a lightbox on click. It seemed there is no such droplet yet, so created it myself by combing the droplet "RandomOrderImages" and the module "MiniGallery". It's a crude solution and could be made much better, but it works fine nevertheless.

You have to install the MiniGallery module (https://forum.WebsiteBaker.org/index.php/topic,22174.0.html) and set the settings. Do not upload images.

Then create a new droplet and call it for example "RandomImagesLightbo x", and add this code:

Code: [Select]
$folder=opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$dir.'/.');
$names = array();
while ($file = readdir($folder))  {
$ext=strtolower(substr($file,-4));
if ($ext==".jpg"||$ext==".gif"||$ext==".png"){
$names[count($names)] = $file;
}
}
closedir($folder);
reset(shuffle($names));
array_unshift($names," ");
if(isset($width)){$width=' width="'.$width.'"';}else{$width="";}
if(isset($height)){$height=' height="'.$height.'"';}else{$height="";}
$count=1;
while(($image=next($names))and(($count<=$num)or(!isset($num)))){
$name=substr($image,0,-4);
if($link=="y"){$images=$images.'<a rel="gallery" class="fancybox" href="'.WB_URL.MEDIA_DIRECTORY.'/'.$dir.'/'.$image.'" target=_blank>';}
if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/'.$dir.'/thumbs/'.$image.'.thumb.jpg')){
$images=$images.'<img src="'.WB_URL.MEDIA_DIRECTORY.'/'.$dir.'/thumbs/'.$image.'.thumb.jpg" alt="'.$name.'" '.$width.$height.' border=0"/>';
}else{
$images=$images.' <img src="'.WB_URL.MEDIA_DIRECTORY.'/'.$dir.'/'.$image.'" alt="'.$name.'" '.$width.$height.' ">';
}
if($link=="y"){$images=$images.'</a>';}
$count++;
}
return $images;

If you compare this to the original RandomOrderImages droplet, you see that I only add the class and rel from the MiniGallery module to the link tag.

Now the original image pops up in a lightbox when clicked  :-D

Use this call:
 
[[RandomOrderImages?dir=some_media_folder_here&num=3&link=y]]

Change the mediafolder and the number of images you want to show.
Logged

Offline svsanchez

  • Posts: 589
Re: Droplet: random image(s) from a media-dir with lightbox popup
« Reply #1 on: August 18, 2012, 03:40:46 AM »
Hello Argos, I installed your droplet and although it shows the images, it shows them at their full size instead of a little thumb. Also, when clicked, it will open the image on a new window. What do I have to change to make it work correctly?
Logged

Argos

  • Guest
Re: Droplet: random image(s) from a media-dir with lightbox popup
« Reply #2 on: August 18, 2012, 10:07:16 AM »
My droplet just combines the random image droplet with the Minigallery module. It seems the Minigallery doesn't work with you. So I suggest you try to get this module to work first, and then try my droplet. So install the Minigallery and add images, and see if it works. I suspect it won't work and there is something wrong. Check out http://minigallery.allwww.nl/ for info.
Logged

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Droplet: random image(s) from a media-dir with lightbox popup
 

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