Random Thumbnails as plugin without duplicates

Hey there, I just spent the day trying to figure this out and finally got it so thought I would share the wealth here. I am not a programmer so forgive if it seems crude, I did what I needed to get it to work.

I needed to show random images from an album on an external page, but found that the random images can end up with duplicates, so my fix:

<?php zp_load_gallery();
?>

<?php //Random Thumbnails, full size image displayed w/ LightBox
zp_load_album('/Hawaii'); // specify album folder
$imageList = ""; // create image list container
for ($i=1; $i<=8; $i++) {
$randomImage = getRandomImagesAlbum();
$imageName = $randomImage->getTitle();
if (strpos($imageList , $imageName)) { // search image list for particular image name, if image name already exists deincrement and continue loop
$i--;
} else {
echo "
\n";
echo 'getSizedImage(getOption('image_size')).'" rel="lightbox[slides]" title="'.htmlspecialchars($randomImage->getTitle(), ENT_QUOTES).'">' .
'<img src="' . $randomImage->getThumb() .
'" alt="'.htmlspecialchars($randomImage->getTitle(), ENT_QUOTES).'"';
echo "/>

\n";
$imageList = $imageList .' '. $imageName; //append image name to image list
}
}
?>

And that's it. It shows 8 random thumbnails which open with a lightbox effect.
Cheers,
Alane

Comments

Sign In or Register to comment.