How can I use PHP and Lightbox to add captions to the images on my site?
I'm still quite a beginner to PHP so h开发者_StackOverflow社区ang with me here..
I've created an (almost recursive) PHP script that looks inside an image directory and its child 'thumbnail' directory. It then creates a loop to select each image and its corresponding thumbnail, generate a link from that thumb and then move on to image #2.
Here is the code for the function I am using:
function imageroll ($imgnum, $album)
{
$i=1;
while($i<=$imgnum)
{
$ii = str_pad($i, 3, "0", STR_PAD_LEFT);
echo "<a class=\"thumb\" href=\"pictures/", $album, "_", $ii, ".jpg\" rel=\"lightbox[", $album, "]\">";
echo "<img src=\"pictures/thumbs/thumb-", $album, "_", $ii, ".jpg\" \/ >";
echo "</a>";
$i++;
}
}
My question, then, is how would I modify this script so that I can use the caption function of Lightbox?
To do this, I would need to add the title
attribute to each image inside the <a>
tag with a string captioning each photo. How can I introduce adding $title to the loop without having to pass 12 different $titles to the function?
Thanks!
How can I introduce adding $title to the loop without having to pass 12 different $titles to the function?
Use an array, that's why they exists. Add your titles to a $titles array and use $title[$i] for accessing each title.
For more information on PHP arrays, check http://php.net/manual/en/language.types.array.php and consult with any good PHP books out there.
Usually lightboxes use title to display captions, so try this:
echo "<a class=\"thumb\" title=\"" . $title . "\" href=\"pictures/", $album, "_", $ii, ".jpg\" rel=\"lightbox[", $album, "]\">";
echo "<img src=\"pictures/thumbs/thumb-", $album, "_", $ii, ".jpg\" \/ >";
echo "</a>";
Let me know if that helps
you can use face-box as a lightbox and insert caption thru it.
精彩评论