on my site, I have a page with the picture of the day
I used the function getRandomImages() for that.
but I would only use the images of a single album, not all images of the gallery.
there is the function getRandomImagesAlbum() for that, but this function does not have an image per day.
how can I do to get a daily random image from a specific album?
thanks for your help
$potd = unserialize(getOption('picture_of_the_day')); $image = NULL; if (date('Y-m-d', $potd['day']) == date('Y-m-d')) { $album = new Album($_zp_gallery, $potd['folder']); $image = newImage($album, $potd['filename']); } if (is_null($image) || !$image->exists) { $image = getRandomImageAlbum($rootalbum); $potd = array('day' => time(), 'folder' => $result['folder'], 'filename' => $imageName); setOption('picture_of_the_day', serialize($potd)); }
Caveat: This code had not been tested.
hello
i have tried to use this script, but it doesn't work.
can you explain how it works and the variables to use?
$potd = unserialize(getOption('picture_of_the_day'));
gets the stored value of the current "image of the day"
$image = NULL;
if (date('Y-m-d', $potd['day']) == date('Y-m-d')) {
If the image of the day is current then create an image object from the stored data
$album = new Album($_zp_gallery, $potd['folder']);
$image = newImage($album, $potd['filename']);
}
if (is_null($image) || !$image->exists) {
If there is no image of the day (or it was obsolete) then get a random image from [b]$rootalbum[/b]--the album object of the album from whence you want the images
$image = getRandomImageAlbum($rootalbum);
$potd = array('day' => time(), 'folder' => $result['folder'], 'filename' => $imageName);
setOption('picture_of_the_day', serialize($potd));
Store the data on this image for future page refreshes (see above)
}
hello
I followed your advice and wrote the following code in the Codeblock1 of a new page.
`
`
but it does not work and I always have a random image that is provided.
Can you help me to solve my problem ?
I may be blind, but I do not see what might be wrong. You will have to do some debugging.
If you keep getting a new image on the refresh it means one of two things.
the first "if" statement is not taking the "true" path. That would indicate that the date is alway different from the POTD date.
the result of setting up the image in the "true" path is failing somehow. That could only be if the image does not somehow exist.
So, we need to determine which case is the issue. Add some debugging code to your theme to see which path you have taken. For instance, in the "true" path place an echo " TRUE path"; and in the code that makes a new random image place echo ' No image:";if (is_null($image_of_the_day) echo " image is NULL"; else echo " image must not exits";
Once you determin what went wrong you can put in debug code to see why.
hello
i follow your instructions like that :
Results :
according to you, where is the problem ?
You have some problem with the album name you have specified. Perhaps it does not exits?
BTW, you must be getting PHP script errors since if the image is NULL, the next statemet that uses it as an object will fault. So I think you best find your CGI error logs and find what errors you are getting. That may also help us.
I tried with a new album.
$specific_album = new Album($_zp_gallery, "mariage");
echo $specific_album->getTitle();
$image_of_the_day = getRandomImagesAlbum($specific_album);
echo $image_of_the_day->getTitle();
where can I find my CGI error logs ?
hello
there is the code :
$specific_album = new Album($_zp_gallery, "mariage");
$image_of_the_day = getRandomImagesAlbum($specific_album);
with that code, $specific_album is an album object, don't you think ?
sorry, I have not read your message correctly.
yes, $specific_album is an album object and not the folder name of the album as you told me in a previous post :
Quote:if (is_null($image) || !$image->exists) {
If there is no image of the day (or it was obsolete) then get a random image from $rootalbum--the album object of the album from whence you want the images
$image = getRandomImageAlbum($rootalbum);
here is the new code :
`
`
with that, it ok, the random image is taken in the good album "mariage".
...but, the image changes each refresh of the browser (the initial problem still the same).
the first "if" is ok, but the album returned by
`
$specific_album = new Album($_zp_gallery, $potd['folder']);
`
seems to be empty
hello
I finally understood the problem
the following code was wrong :
`
if (is_null($image) || !$image->exists) {
$image = getRandomImageAlbum($rootalbum);
$potd = array('day' => time(), 'folder' => $result['folder'], 'filename' => $imageName);
setOption('picture_of_the_day', serialize($potd));
}
`
because it is a copy/cut of getRandomImages() function.
$result['folder'] and $imageName are unknown, so picture_of_the_day didn't have the correct values stored and read.
the following code to have a daily random image from a specific album works well :
`
`
in fact, it would be a nice improvement to modify getRandomImagesAlbum() function to have a daily random image from a specific album.
could you do that in a next release of zenphoto ?