Add a 'no images - click here to add now' message when a user hasn't uploaded any images

description

This snippet displays a message that says "No images - click here to add" when the user hasn't uploaded any images

Thanks to drupalmurf and nevets for contributing the snippet.

instructions

  1. In a text editor paste the following snippet into your user_profile.tpl.php file
    (For instructions on how to get started with your own custom user profile layout click through to the handbook page titled: Customising the user profile layout)
  2. Upload your edited user_profile.tpl.php to your active theme folder

<?php
// Display N most recent thumbnails of images submitted by the user
//  Each thumbnail is linked back to it's image node
// Can optional limit the photos shown by specififying one or taxonomy term id's

// The number of thumbnail images to show
$nlimit = 10;
$taxo_id = array();
// Add one line for each taxonomy term id you want to limit the thumbnails to
// As an example, the following two lines would select images associated with taxonomy terms 36 OR 37
//$taxo_id[] = 10;
//$taxo_id[] = 11;
//$taxo_id[] = 12;
//$taxo_id[] = 13;
//$taxo_id[] = 5;
//$taxo_id[] = 6;
//$taxo_id[] = 20;
//$taxo_id[] = 21;
//$taxo_id[] = 26;
//$taxo_id[] = 32;
// Note, if not taxonomy term ids are specified, the selection is from all the user submitted images

$userid=arg(1);

if (
count($taxo_id) > 0 ) {
   
// Limit images based on taxonomy term id's
   
$taxo_str = implode(',', $taxo_id);
   
$sql = "SELECT n.created, n.title, n.nid, n.changed FROM node n INNER JOIN term_node ON n.nid = term_node.nid AND term_node.tid IN ($taxo_str) WHERE n.type = 'image' AND n.uid = $userid AND n.status = 1 ORDER BY n.changed DESC";
}
else {
   
$sql = "SELECT n.created, n.title, n.nid, n.changed FROM node n WHERE n.type = 'image' AND n.uid = $userid AND n.status = 1 ORDER BY n.changed DESC";
}

$result = db_query_range($sql, 0, $nlimit);
$output = '';
if (
db_num_rows($result) == 0 ) {
 
// No images for the user, do they have permission to add them?
 
if ( user_access('create images', $user) ) {
   
// Yes, show a link for them to use to add their first image
   
$output = l(t('No images - click here to add'), 'node/add/image');
  }
}
else {
  while (
$info = db_fetch_object($result) ) {
   
$node = node_load(array('nid' => $info->nid));
   
$img_tag = image_display($node, 'thumbnail');
   
$link = 'node/' . $node->nid;
   
$output .= l($img_tag, $link, array(), NULL, NULL, FALSE, TRUE);
  }
}
print
$output;
?>

 
 

Drupal is a registered trademark of Dries Buytaert.