display (x) random thumbnails in a page
Last modified: October 5, 2006 - 13:48
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 Only With Link To Profile
<?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.
Rob Safuto
Media Master
http://www.podcastnyc.net
http://www.musicbuggy.com