Closed (duplicate)
Project:
Image
Version:
6.x-1.0-alpha4
Component:
image.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
25 Apr 2009 at 10:03 UTC
Updated:
29 Apr 2009 at 20:44 UTC
This code has been modified to handle multiple TIDS in a comma deliminated list as well as being backwards compatible to a single TID
/**
* @Modification of random image to handle Multiple TIDS
* @{
*/
function image_get_random($count = 1, $tid = 0) {
if ($tid != 0) {
$result = db_query_range(db_rewrite_sql("SELECT DISTINCT(n.nid), RAND() AS rand FROM {term_node} tn LEFT JOIN {node} n ON n.nid = tn.nid WHERE n.type='image' AND n.status = 1 AND tn.tid IN (%d) ORDER BY rand"), $tid, 0, $count);
}
else {
$result = db_query_range(db_rewrite_sql("SELECT DISTINCT(n.nid), RAND() AS rand FROM {node} n WHERE n.type = 'image' AND n.status = 1 ORDER BY rand"), 0, $count);
}
$output = array();
while ($nid = db_fetch_object($result)) {
$output[] = node_load(array('nid' => $nid->nid));
}
return $output;
}
Used with the following block code:
<?php
$numImage = 5;
if (arg(0) == 'node' && ctype_digit(arg(1)) && arg(2)=== NULL ) {
$node = node_load(arg(1));}
$curterms = implode(",",array_keys($node->taxonomy));
$images = image_get_random($numImage,$curterms);
for($i=0;$i<count($images);$i++) {
echo l(image_display($images[$i], 'sidebar'), 'node/'. $images[$i]->nid, array('html' => TRUE));
print_r('<p class="random-image-title">'.$images[$i]->title . '</p>');
}
?>
Comments
Comment #1
joachim commentedOnce we get views support in you can make your own image blocks with any criteria :)
If you're able to help test the patch here, please do! http://drupal.org/node/220295