Get Album's First Image?

Building upon the success of my previous request, I was wondering if anyone would want to help me out with my next issue.

I'm trying to build my image.php such that clicking the image will send you to the next image and so on, until the last image that would in theory send you back to the first. A simple cycle.

I'm thinking it would be useful in this case to have a function call the first image of the album, and get the URL from that. If there's a simpler way, let me know!

Comments

  • trisweb Administrator
    I'd skip an abstraction layer for that and go straight for the class--

    `$firstimage = $_zp_current_album->getImage(0);`
    does exactly what you want :-)
  • It works! Fantastic!
  • i have found the code to click on the image to go the next image. now I would like to implement above as well, so the last will get you back to the first image. but I have no idea where to put the bit of '$firstimage' code...
  • How can I get link by id, if the desired image not in current album? The class above isn't working of course.
  • acrylian Administrator, Developer
    Zenphoto almost never works with the id. It always uses the "name" of an item. To do this you have to setup the album object of the album yourself. See the object model tutorial.
  • I don't want to use the filename, because it's a variable (I can change it anytime), and the id is persistent through the lifetime of image in gallery. I'm trying to make links on images within images (like hotspots).

    How can i get any image full link using id?
  • Be very careful how you change the filename, else you may also change the ID if Zenphoto thinks it is a new image.

    Anyway, there is no way to create a link which uses the ID as the linked object. Zenphoto works only with album/image names.

    If you just want to find an image by id you can always use a SQL SELECT query.
  • Thank you, I'll try.
  • I've ended with the following:

    `

    function getImageLinkbyID($id) {

    $image = query_single_row("SELECT ``albumid`,`filename` FROM " . prefix('images') . " WHERE `id`=" . $id);
    $album = query_single_row("SELECT `folder` FROM " . prefix('albums') . " WHERE `id`=" . $image['albumid']);

    $url = html_encode(getGalleryIndexURL(false)) . "?album=" . $album['folder'] . "%26image=" . $image['filename'];

    return($url);
    }

  • acrylian Administrator, Developer
    More elegant would be to use the object model. Regarding names. Don't confuse the title with the name of an item!
  • I have found a problem.

    On Mobile Safari (on my ipod touch, or on regular Safari with ipod user-agent) link containing url-encoded '&' symbol (%26) shows following error:

    Zenphoto Error: the requested object was not found.
    Album: okhotsk_seashore/coastâ„‘=nuklya_cape_sunset.jpg

    Is it zenphoto or mobile safari bug?
  • The ampersand really should be encoded `&` not `%26`.
Sign In or Register to comment.