Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I like very much lightbox2 but I'd like to have the option to specify just a folder containing the images to show, instead of all the images one by one. So I wrote this PHP snippet but I'm newbie to Drupal (and to PHP too) and I don't know how to transform it in a function that works in Drupal (so to avoid to replicate the whole code for each gallery) and how to integrate it in Drupal and/or Lightbox2 (I tested it only in my localhost windows environment):
$galleryFolder = "sites/default/files/images/my-gallery-dir";
$galleryTitle = "mygallery"; //using this variable in place of pure text does not work
$galleryType = "lightbox"; //using this variable in place of pure text does not work
$galleryLink = "Watch the gallery!";
$firstEntryFlag = true;
$d = dir(getcwd() . "/" . $galleryFolder);
while (false !== ($entry = $d->read())) {
if ($entry !== "." && $entry !== "..") {
if ($firstEntryFlag) {//takes care that only the first image link is visible (my wish)
echo "<a href='$galleryFolder/$entry' rel='lightbox[mygallery]'>$galleryLink</a>";
$firstEntryFlag = false;
} else {
echo "<a href='$galleryFolder/$entry' rel='lightbox[mygallery]' class='lightbox_hide_image'>whatever</a>";
}
}
}
$d->close();
Thanks.
Comments
Comment #1
mmj CreditAttribution: mmj commentedI found a good solution, just add the following PHP code (without PHP wrapper) inside the core module file '..\sites\all\modules\lightbox2\lightbox2.module":
and you'll have a new PHP function available, that you can easily use inside any page (remember to select PHP filter), see the following examples (keep PHP wrapper in this case):
lightbox2_usefolder("images/mycatgallery", "lightshow", "Watch my cat", "mycat");
lightbox2_usefolder("images/mycatgallery", "lightbox", "Watch my cat", "mycat",2);
lightbox2_usefolder("images/mycatgallery", "lightshow", "Watch my cat", "mycat",1);
Especially the chance to use the IPTC field as caption is very useful.
In other words, this simple modification to 'lightbox2' core module adds a "folder" functionality, that is safe because does not interfere in any way with the existing installation.
Comment #2
mmj CreditAttribution: mmj commented