![]() |
|
How to get the accompanying image title and caption for a random image? - Printable Version +- ZenphotoCMS Forum (https://forum.zenphoto.org) +-- Forum: Support (https://forum.zenphoto.org/forum-1.html) +--- Forum: General support (https://forum.zenphoto.org/forum-4.html) +--- Thread: How to get the accompanying image title and caption for a random image? (/thread-5839.html) |
How to get the accompanying image title and caption for a random image? - simon - 2009-09-13 I am using the random image function to display random images on the index.php of my zen photo gallery. I would like to also display the image caption. I would like to place it: (1) as the image description in the image tag. (2) as a separate caption elsewhere on the page. Is this possible, and if so how? Can anyone give me the code snippet? Below is the code I have on my index.php page Any help greatly appreciated! Thanks. S ` <?php $randomImage = getRandomImages(); echo '[img]'.htmlspecialchars($randomImage->getSizedImage(getOption('image_size')) ).'[/img]getTitle(), ENT_QUOTES).'" />';?> ` How to get the accompanying image title and caption for a random image? - sbillard - 2009-09-13 Do it in just the same way as the code you posted gets the title. How to get the accompanying image title and caption for a random image? - simon - 2009-09-14 thanks. Getting the title doesn't seem to be a problem so thats all good - but I am having a problem getting the description. I have been attempting to use `getImageDesc()` but it throws an error. The following code snippet returns the title fine, `'.htmlspecialchars($randomImage->getTitle(), ENT_QUOTES).' ` But, using getImageDesc() throws an error. `'.htmlspecialchars($randomImage->getImageDesc(), ENT_QUOTES).' ` I am obviously doing something wrong, any ideas? Sorry my php skills leave a little to be desired, but your help is genuinely appreciated. S How to get the accompanying image title and caption for a random image? - sbillard - 2009-09-15 You will probably have to improve your PHP skills for a project like this. For instance, I imagine the error thrown said that the method `getImageDesc()` does not exist since its name is `getDesc()`. Review also the functions guides. How to get the accompanying image title and caption for a random image? - simon - 2009-09-15 So, for the benefit of others who may want to achieve the same goal as myself goal: To print the caption or title of an image placed using the random image function use `getTitle()` and `getDesc()` an example of how to use this is: `<?php $randomImage = getRandomImages(); echo '[img]'.htmlspecialchars($randomImage->getSizedImage(getOption('image_size')) ).'[/img]getTitle(), ENT_QUOTES).'" />';?>` and ` '.htmlspecialchars($randomImage->getTitle(), ENT_QUOTES).' ` which outputs the title ` '.htmlspecialchars($randomImage->getDesc(), ENT_QUOTES).' ` which outputs the description The latter examples place the text within `` tags which is what i wanted, but you can edit that if you want. [b]On a point of info: someone might want to update the User Guide: `getDesc()` does not exist since its name is listed as `getImageDesc()`[/b] How to get the accompanying image title and caption for a random image? - acrylian - 2009-09-15 [i]On a point of info: someone might want to update the User Guide: getDesc() does not exist since its name is listed as getImageDesc()[/i] You are wrong actually (beside the doc is generated automatically from the files directly). `getImageDesc()` is a template function depending on the image context: http://www.zenphoto.org/documentation/functions/_template-functions.php.html#functiongetImageDesc `getDesc()` is a direct image class method and needs to be used on the image object. http://www.zenphoto.org/documentation/classes/_Image.html#methodgetDesc How to get the accompanying image title and caption for a random image? - simon - 2009-09-15 I stand corrected - I did look, but I didn't find it. |