Latest (x) image in block

Last modified: June 6, 2006 - 03:26

<?php
 
/*
   * Used with image.module
   * Tested with Drupal 4.6.x
   * To modify change the value of $number to
   * the number of images that you wish to show
   */

 
$number = 1;
 
$thumbs = 0;
  while (
$thumbs<$number) {
   
$images = (image_get_latest($count = 1, 0));
    print
l(image_display($images[0], 'block'),'node/'.$images[0]->nid, array(), null, null, FALSE, TRUE);
   
$thumbs++;
  }
?>

Modified from http://drupal.org/node/53987

Latest x Images (Drupal 5.x)

vinayras - July 13, 2007 - 18:54

<?php
$numImage
= 5;
$images = image_get_latest($numImage);

for(
$i=0;$i<count($images);$i++) {
            echo
l(image_display($images[$i], 'thumbnail'), 'node/'. $images[$i]->nid, array(), NULL, NULL, FALSE, TRUE);
}
?>

This works fine on Drupal 5.x

Vinay Yadav
PHP / Drupal Specialist
http://www.vinayras.com

And for drupal6

jorisx - July 22, 2008 - 23:45

And for drupal6

<?php
$numImage
= 3;
$images = image_get_random($numImage);
//$images = image_get_latest($numImage);

for($i=0;$i<count($images);$i++) { 
    echo
l(image_display($images[$i], 'thumbnail'), 'node/'. $images[$i]->nid, array('html' => TRUE));
}
?>

change numImage for the amount of images
to switch between random and latest: uncomment the line that says "image_get_latest" for the latest images ...

Http://www.reloadmedia.com

How to change code to pull from another image size

superflyman - January 4, 2009 - 16:42

Great snippet, works like a charm. However, I now have a situation where I need to use a size other than the thumbnail in this display. I would like to be able to create a new image size, let's call it "frontpage" for now, and have the code display this size instead of "thumbnail". Simply changing the 'thumbnail' in the code to 'frontpage' will not work. Is this because thumbnail is a default system value and frontpage is not? Any thoughts on how to tweak this would be super appreciated. Thanks!

 
 

Drupal is a registered trademark of Dries Buytaert.