On album.php I am looking to display the first image of the album as a preview to the album if possible. Basically to be able to display the current albums first image adjacent to the thumbnails. In fact any image would do from that album but ideally the first.
Sorry, I am not a coder but would really appreciate the help
Might have to be more complicated than that... go through the classes and $_zp_current_album (underlying Album class, available in your theme technically) to get what you need. Take a look at classes.php and the functions available there and you might find something :) Sorry I can't help more.
Oh [b]please[/b] just use the objects, they're fully featured!
`
[img][/img]">
`
See how simple? This should work (barring any code mistakes, I haven't tested it or anything). This way you can change the size or whatever you like. If you want a custom sized image, use this line instead (replacing the $size, $width etc. with numbers or nulls):
$first_url = $first_image->getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy);
It helps to know the classes inside-out of course ;-) I should write some good documentation, but the code is clean enough to read.
Thanks for the help and I agree the code is clean enough to read but I am well and truely punching above my weight with pretty much any PHP! (Note to self must get up to speed on PHP, JS, Ruby etc :-) )
I digress..... I am still having trouble with this though. I get the following error when trying to use the code,
[quote]
"Call to a member function on a non-object in ......"
[/quote]
This is refering to,
`
$first_url = $image->getSizedImage(zp_conf('image_size'));
`
I can't see what I am missing. I am using the 1.0.3 release.
Try replacing the lines
`$first_image = new Image($_zp_current_album, $images[0]);
$first_url = $image->getSizedImage(zp_conf('image_size'));
$first_desc = $image->getDesc();`
with
`$first_image = new Image($_zp_current_album, array_shift($images));
$first_url = $first_image->getSizedImage(zp_conf('image_size'));
$first_desc = $first_image->getDesc();`
Two problems: first, the array, $images doesn't use numbers for keys, it uses image names. Thus, you can't just get the first one by $images[0] (I forgot ;-) The function array_shift gives you the first item off any array, regardless of how it's organized, so it works better. Second problem was that I used $image instead of $first_image for the variable names in the second two lines.
I tested it this time, so it should be good. :-)
So something you should learn from this are variables and variable names (the ones you use have to match the ones you define), and array indices. Those are pretty general programming ideas, not specific to PHP, so very useful concepts.
Tris, I really appreciate your help but I don't seem to be getting much closer. With the changes you have made, the output html is as follows with mod rewrite,
`
[img]/~website path~/~album name~/image/595/[/img]
`
Without mod rewrite,
`
[img]/~website path~/zen/zen/i.php?a=test&i=&s=595[/img]
`
This occurs regardless of what album I am in.
(For clarity, I am runnning this on the album.php page) Thanks.
bbish-
note above a few comments, tris mentions the use of getcustomimage. that's probably what you want to use instead of getsizedimage, as getsizedimage will return the default image size from the zp-config file. getcustomimage will in turn show you a custom image size of your choosing (note the size, width, height params in that function).
Does that help?
That's why the 595 shows for the size parameter because if you are pulling from the unchanged (default) zp-config, the size is set to 595.
Thanks for looking ThinkDreams but unfortunately it does not help :-(
I understand that the default parameter for the image size and this is returned from "zp_conf('image_size')". I have tried both techniques (custom image size and default) but with no success. I was simply trying to get the basic function to return the image name and description and then I would worry about the dimensions of the image returned. Small steps etc.
As per the html I posted above, the problem is not with the default image size returned (that bit of the function works) but the fact it doesn't return the image name or any value for the description (alt text).
e.g
Yep, so let's recap: this is what we have for this:
`
[img][/img]">`
That should be correct.
The URL's in your images above are also correct, I don't see anything wrong with them. Zenphoto's images are all passed through a script, they're never directly accessed -- thus, you'll get "/zen/i.php?a=album&i=image&w=400" from the code above, and that's how it's supposed to be. With mod_rewrite on, it's even cleaner, "/~album name~/image/595" is perfect, and should work. Is that image not showing?
Let's clarify: What do you want to do exactly?
Also, can we see your site? Thanks!
I am probably not explaining myself very well.
To sum up, the image is not being displayed and neither is the description as the alt text ( I understand that not all my images have descriptions but some do and they should be displayed).
@ Tris, can we forget about mod rewrite for the moment? From your reply above, no. 5230, you said,
[i]"…..thus, you'll get '/zen/i.php?a=album&i=image&w=400' from the code above, and that's how it's supposed to be."[/i]
Well I am not getting that (as per my earlier reply), it is not returning the html for the image part. e.g the "&i="part doesn't have the image name after it. Unless I am mistaken, how is the browser supposed to render the page and display the image if it isn't stated in the image tags?
“/zen/zen/i.php?a=album&i=&s=400â€
Hopefully you understand my problem now.
Oy, I forgot, old version... old notation...
Replace:
$first_image = new Image($_zp_current_album, array_shift($images));
With:
$first_image = array_shift($images);
And when you upgrade to 1.0.4, out this week most likely, you'll have to go back to the first one ;-) Sorry for the confusion.
I just tried this code, it does display the image but above it I get the following errors:
`Warning: Missing argument 3 for getcustomimage() in /x/x/x/x/zen/class-image.php on line 201
Warning: Missing argument 4 for getcustomimage() in /x/x/x/x/zen/class-image.php on line 201
Warning: Missing argument 5 for getcustomimage() in /x/x/x/x/zen/class-image.php on line 201
Warning: Missing argument 6 for getcustomimage() in /x/x/x/x/zen/class-image.php on line 201
Warning: Missing argument 7 for getcustomimage() in /x/x/x/x/zen/class-image.php on line 201`