Random Images?

I am trying to display several random images without the same image repeating.
is it possible that I could change the current Random Image Function included in the Effervenscence to do this?

`

// Get Random Images function getRandomImages() {$result = query_single_row('SELECT '.prefix("images").'.filename,'.prefix("images").'.title, '.prefix("albums").'.folder FROM '.prefix("images").' INNER JOIN '.prefix("albums").' ON '.prefix("images").'.albumid = '.prefix("albums").'.id ORDER BY RAND() LIMIT 2');$image = new Image(new Album(new Gallery(), $result['folder']), $result['filename']);return $image;}function getURL($image) {if (zp_conf('mod_rewrite')){return WEBPATH . "/" . pathurlencode($image->getAlbumName()) . "/" . urlencode($image->name);}else{return WEBPATH . "/index.php?album=" . pathurlencode($image->getAlbumName()) . "&image=" . urlencode($image->name);}}

`

-Raz88

Comments

  • Raz88 Member
    Is it possible to get the random image to directly linked to the image its displaying, like on http://www.thinkdreams.com/zenphoto/. Because right now I am using the default function that comes with Effervenscence Theme. But when clicking the image it goes to the album, where the image is located, instead of the specific image itself.

    Example, This is what is showing up now:

    http://www.example.com/blog/gallery/test/

    this is what I want:

    http://www.example.com/blog/gallery/test/image.jpg

    -Raz88
  • Yes. That is odd. I'm looking into it. Not sure why it's doing that but it's doing it for me too. Might be something strange between the latest zenphoto SVN and the random image code, but everything seems to check out OK.

    What version of zenphoto are you running?
  • Tristan-

    Would zenphoto in its latest SVN version present any differences to this function? I'm trying to figure out why the same function works differently across a couple installations (and themes). I hadn't noticed before that it was directing the URL to the album, not the image, so it seems to be "truncating" the image portion of the URL, even though the image displays correctly. So the DB query is OK, might be something that is wrong in the getURL function that is causing trouble.

    Could you take a peek and see if something is amiss? I can't figure out what's causing it.

    `function getRandomImages() {

    $result = query_single_row('SELECT '.prefix("images").'.filename,'.prefix("images").'.title, '.prefix("albums").'.folder FROM '.prefix("images").' INNER JOIN '.prefix("albums").' ON '.prefix("images").'.albumid = '.prefix("albums").'.id ORDER BY RAND() LIMIT 1');

    $image = new Image(new Album(new Gallery(), $result['folder']), $result['filename']);

    return $image;

    }

    function getURL($image) {

    if (zp_conf('mod_rewrite'))

    {

    return WEBPATH . "/" . pathurlencode($image->getAlbumName()) . "/" . urlencode($image->name);

    }

    else

    {

    return WEBPATH . "/index.php?album=" . pathurlencode($image->getAlbumName()) . "&image=" . urlencode($image->name);

    }

    }

    `
  • Doing more looking, it's definitely related to the SVN changes (although I'm not sure what - maybe the new caching stuff?). I'm at SVN 438 on my Bushwood gallery, and 1.0.8.2 on my thinkdreams gallery. It works fine at http://www.thinkdreams.com/zenphoto.
  • No worries. I fixed it another way. Still might be curious as to why `$image->name` didn't display the image filename at the end of the link, but `$image->getFileName()` does.

    anyway, replace the getURL code with this in your customfunctions.php file:
    (Note the use of `$image->getFileName()` instead)

    `function getURL($image) {

    if (zp_conf('mod_rewrite'))

    {

    return WEBPATH . "/" . pathurlencode($image->getAlbumName()) . "/" . urlencode($image->getFileName());

    }

    else

    {

    return WEBPATH . "/index.php?album=" . urlencode($image->getAlbumName()) . "&image=" . urlencode($image->getFileName());

    }

    }`

    Let me know how it works for you. It seems to work OK on Bushwood now. (http://www.bushwoodworking.com)
  • Raz88 Member
    Thanks, its working now. Its definitely something with the new SVN. But is it possible to do what my first post asks.

    -Raz88
  • I imagine so. What you'd have to do is write a function that checks the first random, and then if the second random is the same, then re-run the random function to obtain a new second image. That's a rough idea of how I see it.

    No computer random function will be 100% completely random due to the nature of computers and random numbers, so that is my best guess on how it may work.

    Other programmers on the board may have other ideas to provide on how it may work more efficiently.
Sign In or Register to comment.