Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Here's a block that works like random image, but pulls the images from a chosen gallery/category.
$gallery_name='Enter the name of the gallery here';
$term = taxonomy_get_term_by_name($gallery_name);
$tid = $term[0]->tid;
$thumbs = 0;
$images_arr = (image_get_random($count = $thumbs, $tid));
foreach ($images_arr as $images){
print l(image_display($images, 'thumbnail'),'node/'.$images->nid, array(), null, null, FALSE, TRUE);
}
An alternative version slightly modified to display only the image. This function just shows the image without any links.
$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 image_display($images[0], 'preview');
$thumbs++;
}
Comments
for 6-x
is it possible...
do include only showing images that have a certain 5-star rating? or perhaps images that are rated 3 stars or higher so that the random images are chosen from the better quality images?
this would be incredibly useful....
styling
How to put html tags around the images so I can style them?
http://twitter.com/tosho
How does this work exactly?
I can't get it to work-
I create a block, enable PHP input- paste the following code, except I replace the name of the gallery in the right area.
But dosent work.
What else do I need to specify apart from image gallery name?
Hi, I have exactly the same problem: created a new block with following php code but it's not visible anywhere:
What else do I have to configure or add? I'm using Drupal 6 and Image module 6.x-1.0.
Thanks for your support.
PHP filter
It works on Drupal 6! You must enable the module PHP filter, then create a new block pasting the above code and selecting PHP Code as input format.