Hi, I'm using printImageDesc() to display the Image description just under the thumbnails in the gallery view, but I'd like to limit the output to a certain fixed limit number of characters and add a link to the image item. Just like some News items. I know this shouldn't be difficult and I've tried something unsuccesfully but I'm not finding an example (that I can understand! ;-) in the docs ...
That's my code now:
Use this to get the plain desc:
https://docs.zenphoto.org/1.5.x/function-getImageDesc.html
That contains HTML formatting. There is also: https://docs.zenphoto.org/1.5.x/function-getBareImageDesc.html
Or the object model if there is a current image:
$_zp_current_image->getDesc();
Rhen use https://docs.zenphoto.org/1.5.x/function-truncate_string.html to shortend the text. Use this with the "bare" version.
To keep formatting of HTML better use this as that try to fix invalid html (to work properly your server PHP needs the the tidy class installed):
https://docs.zenphoto.org/1.5.x/function-shortenContent.html
add a link to the image item
The iamge item would be the single image page.
https://docs.zenphoto.org/1.5.x/function-getImageURL.html
You should see that on your theme's album.php
Or the object model if there is a current image:
$_zp_current_image->getLink();
The object model version would be
If you mean the original full image itself:https://docs.zenphoto.org/1.5.x/function-getFullImageURL.html
Or the object model if there is a current image:
$_zp_current_image->getFullImageURL();
However I made this choice mainly because I've noticed that shortenContent() very cleverly closes any opened tag eventually interrupted
Yes, "fixing" broken HTML is the main purpose of this. For plain string truncation you can just use native PHP functions.
A further step would be to print the link only when the shortenContent() is used, but I don't know how to write the if statement...
Rather basic native PHP actually. just check the length of the description to be larger than your expected length using strlen. Of course that will also count HTML elements.