Images from node_images.module in a block

Last modified: June 23, 2007 - 10:59

This block displays the node images (using node_images.module) form the current node. You can set the number of images to display in the block.

<?php
//use with node_images.module
//displays node images from the current node
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
 
$node = node_load(arg(1));//get node id
 
$max = variable_get('block_images', 3); //set the number of images to display
 
$sql = db_query('SELECT * FROM {node_images} WHERE nid=%d AND status=1 ORDER BY weight', $node->nid);
  while ((
$data = db_fetch_object($sql)) && ($count < $max)) {
     
$alt = $data->description;//use description as image alt text
     
$output = theme("image", $data->filepath, $alt);
     
$count++;
      print (
$output);
  }
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.