![]() |
|
random image from within an album - Printable Version +- ZenphotoCMS Forum (https://forum.zenphoto.org) +-- Forum: Support (https://forum.zenphoto.org/forum-1.html) +--- Forum: General support (https://forum.zenphoto.org/forum-4.html) +--- Thread: random image from within an album (/thread-1567.html) |
random image from within an album - sbillard - 2007-07-28 Can anyone give me an SQL query that would get a random image from within the images in an album/subalbum set? I'd like something like the getRandomImage function, but would like to limit the selection to those images within a particular album and its children. random image from within an album - zittoune - 2007-07-30 Hello, It's a good functionnality that I also wanted, so I tried to work on it and it seems to work ! I did it on the efferverscence theme. I added this function to the customfunctions.php in the effervescence them directory : $result = query_single_row("(SELECT zenphoto_images.filename, zenphoto_images.title, zenphoto_albums.folder FROM zenphoto_images INNER JOIN zenphoto_albums ON zenphoto_images.albumid = zenphoto_albums.id WHERE zenphoto_albums.id = ".getAlbumId().")UNION(SELECT zenphoto_images.filename, zenphoto_images.title, zenphoto_albums.folder FROM zenphoto_images INNER JOIN zenphoto_albums ON zenphoto_images.albumid = zenphoto_albums.id WHERE zenphoto_albums.parentid = ".getAlbumId().") ORDER BY RAND( ) LIMIT 1"); $image = new Image(new Album(new Gallery(), $result['folder']), $result['filename']); return $image; }` It uses the function getAlbumId() that I added in the template-functions.php in the zen directory : global $_zp_current_album; return $_zp_current_album->getAlbumId(); }` And then you just have to add the same code as in the index.php to add the random picture but with That's it random image from within an album - sbillard - 2007-07-31 Works great, almost. I changed the `function getRandomImagesAlbum() { $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 WHERE ".prefix('albums').".id = ".getAlbumId(). ")UNION(SELECT ".prefix('images').".filename, ".prefix('images').".title, ".prefix('albums').".folder FROM ".prefix('images'). " INNER JOIN ".prefix('albums')." ON ".prefix('images').".albumid = ".prefix('albums').".id WHERE ".prefix('albums'). ".parentid = ".getAlbumId().") ORDER BY RAND( ) LIMIT 1"); $image = new Image(new Album(new Gallery(), $result['folder']), $result['filename']); return $image; } ` random image from within an album - Photoxite - 2009-07-09 Non programmer here so my question might be sadly simple. I'm not using the efferverscence theme (using zenpage default) and do not have a customfunctions.php to add code to. Any suggestion how/where to modify zenpage theme to accomplish the same random image idea? random image from within an album - sbillard - 2009-07-09 You can always create a customfunctions.php script and load it in the theme. As you have probably guessed, looking at how Efferevescence+ does this would be a good start. |