Posts: 12
Threads: 5
Joined: Dec 2011
2013-03-13, 00:59:08
(This post was last modified: 2013-03-18, 07:09:10 by Alb.)
Hello!
I use the following code to display a random thumbnail to my website.
PHP Code:
<?php get_i18n_gallery('gallery1',array('url'=>'gallery1', 'thumb'=>'random')); ?>
This code selects a random picture from my gallery1 and display the thumbnail.
I want to select random pictures from 2 or more galleries and to display the random thumbnail.
How can I integrate gallery2, gallery3... in this query?
I tried with array but didn't succeed, maybe I didn't make the correct array code. Any suggestion?
Thanks
Posts: 2,094
Threads: 54
Joined: Jan 2011
(2013-03-13, 00:59:08)Alb Wrote: I use the following code to display a random thumbnail to my website.
...
How can I integrate gallery2, gallery3... in this query?
It's not possible.
Posts: 6,266
Threads: 181
Joined: Sep 2011
You could pick the gallery at random also.
PHP Code:
$gallery = 'gallery'.rand(1,3);
get_i18n_gallery($gallery,array('url'=>$gallery, 'thumb'=>'random'));
Posts: 12
Threads: 5
Joined: Dec 2011
Thank you for your replies. I succeed to make it work. My galleries has different names like what I write in the first post. They are not gallery1,gallery2,gallery3....
they are my-first-gallery, another-gallery-name, etc...
I use this code to switch them:
PHP Code:
<?php
$gallery = Rand (1,2);
switch ($gallery) {
case 1:
get_i18n_gallery('my-first-gallery',array('url'=>'my-first-gallery', 'thumb'=>'random'));
break;
case 2:
get_i18n_gallery('another-gallery-name',array('url'=>'another-gallery-name', 'thumb'=>'random'));
break; }
?>
And in case I want to add another gallery I should add another case and edit the rand() max.
You think is ok this code? As long as it works I think is good, but better double check if can be a bug or something .
Thanks
Posts: 6,266
Threads: 181
Joined: Sep 2011
Then you just stick the names in an array and use the rand as the index when fetching it.
Posts: 6,266
Threads: 181
Joined: Sep 2011
Ill post code later if you can't figure it out
Posts: 12
Threads: 5
Joined: Dec 2011
(2013-03-18, 03:04:44)shawn_a Wrote: Ill post code later if you can't figure it out
It works for me the way I did. I don't want to make things complicated. I understand the way the code works and I know what to add/delete in case I want to make changes to the gallery.
Maybe you have a simple version but if it works like this, I just leave it.
Thanks