prev next question

I want the next button to link to the first image of the album when the last image is showing. I don't see a function that give me the link to the first image.
any ideas ...?

Comments

  • acrylian Administrator, Developer
    There is no function/option for that. This should work:
    `if (hasNextImage()) {

    } else {

    $firstimage = $_zp_current_album->getImages(0);

    echo "Next

    }`

    (Codetypos on purpose because the "damm" forum makes a real link out otherwise...)
  • or you could possibly just add a function like getPrevImageURL() and call it getFirstImageURL() in template-functions.php, something like this I think:

    `

    /**

    * Returns the url of the first image in current album.

    *

    * @return string

    */

    function getFirstImageURL() {

    if(!in_context(ZP_IMAGE)) return false;

    global $_zp_current_album, $_zp_current_image;

    $firstimg = $_zp_current_album->getImage(0);

    return rewrite_path("/" . pathurlencode($firstimg->album->name) . "/" . urlencode($firstimg->filename) . im_suffix(),

    "/index.php?album=" . urlencode($firstimg->album->name) . "&image=" . urlencode($firstimg->filename));

    }`
  • @acrylian: echo `Next` didnt work. i had to change $firstimage to $firstimage[0]. That did the trick :)thanks.

    @gerben: thanks for looking in to it, i decided to use acrylian's method because i will forget that i changed the functions file and with an update i will get lost :) This way it is easy for me to change if necessary.
  • I actually just added this on my site, i just made that getFirstImageURL() function and similarly a getLastImageURL() function to get the url to the last image in the album.
    to get the last image I used:

    '$lastimg = $_zp_current_album->getImage($_zp_current_album->getNumImages() - 1);'

    and then I changed the links to the next and previous picture in image.php like this:

    'a href="<?php if (hasPrevImage()){echo getPrevImageURL();} else{echo getLastImageURL();}?>"'

    'a href="<?php if (hasNextImage()){echo getNextImageURL();} else{echo getFirstImageURL();}?>"'

    This works fine.
  • acrylian Administrator, Developer
    @MarcelSpijker: Ah, sorry, that typo was without purpose..:-)

    @gerben: Good one, too.
  • Would these functions also work to add "first" and "last" image _in addtion_ to prev/next?

    <<First>> <<Prev>> <<Next>> <<Last>>
  • Yes, they just return a link to the first and the last picture.
  • acrylian Administrator, Developer
    As a note we have included both functions in the next nightly build.
Sign In or Register to comment.