[support] tweaking php to get random images from multiplegalleries

sander-martijn sander at sander-martijn.com
Wed Aug 22 14:48:06 UTC 2007


I second that.  David made the same recommendation to me a few days ago 
to the same question and I went with that option.  Not only is it easier 
to set up and maintain than the code before, you'll immediately start 
thinking of all the other things views is great for.  But most 
importantly if you pass this off to a savvy admin (but nonprogrammer) 
they would be able to add or subtract galleries or make other changes to 
the criteria/configuration without having to come back to you. 

.s

Metzler, David wrote:
> Also,
>
> Would really recommend you explore using views module.  You create a
> view that returns one node in the block, and  set sort order to random.
>
>
> You can get more than random images with this, but random anything! 
>
> Selecting which nodes qualify is just adjusting the view on the filter
> criteria. 
>
> Dave 
>
> -----Original Message-----
> From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On
> Behalf Of Fabio Varesano
> Sent: Wednesday, August 22, 2007 6:22 AM
> To: support at drupal.org
> Subject: Re: [support] tweaking php to get random images from
> multiplegalleries
>
> 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++;
>> }
>> ?>
>>     
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>   

-- 
------------------------------------------------------------------------

sander-martijn <mailto:sander at sander-martijn.com>
interface developer | architect
sander at sander-martijn.com <mailto:sander at sander-martijn.com>
www.sander-martijn.com <http://www.sander-martijn.com>

------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20070822/d087f9e7/attachment.htm 


More information about the support mailing list