I'm trying to figure out if I can mod Gallery to do one (or a combination) of the following:
a) Specify short captions (preferably, although this could be something as basic as just the photo filename) for each photo, which would be visible on the album thumbnail page; then have a complete (potentially lengthy) descriptive "caption" visible on the single-photo page (both the resized and full-size views).
b) Alter the album page layout so the caption can be wider than the thumbnail (to avoid line wrapping every two or three words).
Would this require modifications to 'view_album.php', and possibly to 'albums.php' and/or 'view_photo.php'? Or, would I need to make changes in one (or more) of the 'html_wrap' files? Here's hoping someone can give me some helpful hints! I'm no programmer, but I'm fairly confident reading code, and making changes as long as I know exactly what to do.
Thanks, and best regards!
Posts: 8
Here's my solution for the long caption problem. It cuts up the caption every time is sees <br>, so only the text before the first <br> is diplayed when viewing the thumbnail. If the first line is still bigger than "$shortCaptionLength", then we add "..." to the end of the chopped caption. It may not be the most elegant peice of programming but it works for me.
In view_album.php REPLACE
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>
echo($gallery->album->getCaption($i));</TD></TR></TABLE><!-- BBCode End -->
WITH
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>
/* Current item is a photo
* This is the solution for the long captions.
* The string $captionText is split up so that if it contains
* <br>, only the first line of the caption will be shown on the
* gallery viewing page. Then the visitor will see the full caption
* when viewing the full-sized photo.
* Known problem: if <br> is at the very beginning of the caption, Gallery
* will display "Array" instead of caption text.
*/
$captionText = $gallery->album->getCaption($i);
$shortCaptionLength = 75;
// edit line above to number of characters you want displayed on caption
$myCaptionText = explode("<br>", $captionText);
// put each line ended with <br> in a line of the array $myCaptionText
if (strlen($myCaptionText[0]) > 0) {
$newCaptionText = $myCaptionText[0];
// grap first line of caption
}
else {
$newCaptionText = $myCaptionText;
// caption was only one line
}
if (strlen($newCaptionText) > $shortCaptionLength) {
$newCaptionText = substr($newCaptionText, 0, $shortCaptionLength);
// caption is too long, chop it
$newCaptionText = $newCaptionText . "...";
// add trailing "..."
}
echo $newCaptionText;
// display our short caption </TD></TR></TABLE><!-- BBCode End -->
Posts: 1301
Eion, thanks for this!
I removed the comments entirely on the thumbnails in my own gallery setup, but I maintain a charity website (www.prda.org/gallery/) that uses Gallery and tried it there just now and it works perfectly.
Thanks again!
Posts: 2
Thanks for the tip, Eoin. I'll give this a try and see if I get the desired result.