How to get titles for lightbox images

I am using php lightbox (this one is http://www.fatbellyman.com/webstuff/lightbox_gallery/index.php ) to display thumbnails and images automatically. I would like the titles and descriptions of the images to appear on large lightbox images pulled from a separate list (text file?). If possible, do it without using the best database.

This is on my gallery page:

<?php include 'lightbox_display_function.php'; ?>
<?php lightbox_display('apparel/soiled/icarus/', 'lightbox[icarus]'); ?>

      

And this is lightbox_display_function.php:

<?php function lightbox_display($dir_to_search, $rel){
        $image_dir = $dir_to_search;
        $dir_to_search = scandir($dir_to_search);
        $image_exts = array('gif', 'jpg', 'jpeg', 'png');
        $excluded_filename = '_t';
            foreach ($dir_to_search as $image_file){
            $dot = strrpos($image_file, '.');
            $filename = substr($image_file, 0, $dot);
            $filetype = substr($image_file, $dot+1);
            $thumbnail_file = strrpos($filename, $excluded_filename);
                if ((!$thumbnail_file) and array_search($filetype, $image_exts) !== false){
echo "<a href='".$image_dir.$image_file."' rel='".$rel."'>
<img src='".$image_dir.$filename."_t.".$filetype."' alt='".$filename."' width='70' height='70' title='$filename'/>
</a>"."\n";
                }
            }
    }

      

+3


source to share


1 answer


Do you have some example code of how you have the page structured at the moment from my head, could you hard copy them into some associative array?

Provide a filename for the image so you can concatenate the headers with the required file?

If you post what you have so far, we could take a look and hopefully make suggestions.

- Update -

Hardcore an array for the page before you call it, and include the array as a parameter so that the elements in it can be connected to the corresponding images in the function.



<?php include 'lightbox_display_function.php'; ?>
<?php
$titleArray=array();
$titleArray['RedCar.jpg']="Picture of red car";
$titleArray['BlueCar.jpg']="Picture of blue car";
$titleArray['GreenCar.jpg']="Picture of green car";
lightbox_display('apparel/soiled/icarus/', 'lightbox[icarus]',$titleArray); 
?>

      

So, now in the function we have information for working with

    <?php function lightbox_display($dir_to_search, $rel,$titleArray){
            $image_dir = $dir_to_search;
            $dir_to_search = scandir($dir_to_search);
            $image_exts = array('gif', 'jpg', 'jpeg', 'png');
            $excluded_filename = '_t';
                foreach ($dir_to_search as $image_file){
                $dot = strrpos($image_file, '.');
                $filename = substr($image_file, 0, $dot);
                $filetype = substr($image_file, $dot+1);
                $thumbnail_file = strrpos($filename, $excluded_filename);

                $title="";
                if (array_key_exists($filename, $titleArray)) { //check if the filename matches a key in the array
                   $title = $titleArray[$filename]; //match, so set $title to equal the title set for that image name in the array
                }

                if ((!$thumbnail_file) and array_search($filetype, $image_exts) !== false){
                     //At this point $title can be included in the echo or used in some fashion, put is paired up with the appropriate image.
                     echo "<a href='".$image_dir.$image_file."' rel='".$rel."'>
                     <img src='".$image_dir.$filename."_t.".$filetype."' alt='".$filename."' width='70' height='70' title='$filename'/>
                     </a>"."\n";
                    }
                }
        }

      

I haven't tested this, but it should give you something to work with, theory if nothing else.

0


source







All Articles