[support] tweaking php to get random images from multiple galleries

Fabio Varesano fabio.varesano at gmail.com
Wed Aug 22 13:21:51 UTC 2007


You might want to try this:

<?php
   // set the names of the galleries you want to enable
   $galleries = array("One", "Two", "Three", "Four", "Five");
   $gallery = $galleries[array_rand($galleries)];

   $term = taxonomy_get_term_by_name($gallery);
   $tid = $term[0]->tid;
   $thumbs = 0;
   while ($thumbs<1) {
   $images = (image_get_random($count = 1, $tid));
   print l(image_display($images[0],
'thumbnail'),'node/'.$images[0]->nid, array(),
null, null, FALSE, TRUE);
   $thumbs++;
}
?>

I did not tested it.

Please post it on the handbook if you are successful with it.


Hope this helps,

Fabio Varesano

will hall wrote:
> hi all, this is from the -> PHP snippets section of the drupal website: 
> Customization and theming » PHP snippets » PHP block snippets
> Random image from a particular category/gallery
> 
> can someone help tweak this so you can have it grab the images from 
> several diferent galleries, rather than just one?
> 
> i'm very new to php, but i don't think adding several gallery names, 
> separated by commas, will work...
> 
> thanks!
> 
> -- will
> 
> <?php
>    $gallery_name='Enter the name of the gallery
> here';
>    $term = taxonomy_get_term_by_name($gallery_name);
>    $tid = $term[0]->tid;
>    $thumbs = 0;
>    while ($thumbs<1) {
>    $images = (image_get_random($count = 1, $tid));
>    print l(image_display($images[0],
> 'thumbnail'),'node/'.$images[0]->nid, array(),
> null, null, FALSE, TRUE);
>    $thumbs++;
> }
> ?>


More information about the support mailing list