Member
Member
simon   2009-09-13, 08:19
#1
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).'" />';?>

`
Member
Member
sbillard   2009-09-13, 22:12
#2
Do it in just the same way as the code you posted gets the title.
Member
Member
simon   2009-09-14, 11:19
#3
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
Member
Member
sbillard   2009-09-15, 02:01
#4
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.
Member
Member
simon   2009-09-15, 09:15
#5
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]
Administrator
Administrator
acrylian   2009-09-15, 10:26
#6
[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
Member
Member
simon   2009-09-15, 14:39
#7
I stand corrected - I did look, but I didn't find it.
  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.