Community Documentation

display (x) random thumbnails in a page

Last updated May 18, 2009. Created by Dublin Drupaller on June 13, 2005.
Edited by bekasu, pwolanin. Log in to edit this page.

PLEASE NOTE! The following snippet is user submitted. Use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

<?php
/**
* This php snippet displays (x) random thumbnails with a link to
* the full images in a page.
*
* (assumes you already have the IMAGE.MODULE installed)
*
* To increase/decrease the number of thumbnails listed
* change the $thumbs field to suit.
*
* Tested and works with drupal 4.6
*/

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

Image Twist

<?php
/*
* This php snippet loads up a random user object and displays their avatar (sized to 100 by 100) with a link to their profile.
* $count controls (x) number of users to display
* $no_avatar controls the path to the default avatar image to display.
*
* tested and works with drupal 4.6.x
*/
$count = 12;
$no_avatar = "images/musicbuggy-user-img.png";
$result = db_query_range(db_rewrite_sql("SELECT * FROM {users} u ORDER BY RAND()"), 0, $count);
  while (
$user_info = db_fetch_object($result)) {
  if(
$user_info->uid){
      if(
$user_info->picture){
      print
"<a href=\"/user/$user_info->uid\" title=\"View $user_info->name's profile.\">";  print '<img src="/'.$user_info->picture.'" height=100 width=100 alt="Visit this user profile.">'; print '</a>';
      }
      else {
      print
"<a href=\"/user/$user_info->uid\" title=\"View $user_info->name's profile.\">";  print '<img src="/'.$no_avatar.'" height=100 width=100 alt="Visit this user profile.">'; print '</a>';
      }
    }
  }
?>

A little bit of a twist on this one. I've removed the text link to the profile and just the avatar links to the profile. Also added a bit of code to standardize image sizes to 100x100.

About this page

Drupal version
Drupal 4.6.x

Archive

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.