Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Need some help with displaying a random thumbnail from 2+ galleries
#1
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
Reply
#2
(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.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#3
You could pick the gallery at random also.

PHP Code:
$gallery 'gallery'.rand(1,3);
get_i18n_gallery($gallery,array('url'=>$gallery'thumb'=>'random')); 
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#4
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
Reply
#5
Then you just stick the names in an array and use the rand as the index when fetching it.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#6
Ill post code later if you can't figure it out
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#7
(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
Reply




Users browsing this thread: 1 Guest(s)