As we all may already know, Drupal core recent comment block is what we can say beautiful, It is really basically coded without the respect of aesthetically designed element considered.

This blog article will somehow improve the functionality of the Drupal core comment block by allowing the block to show the user picture.

We will do the theming utilizing drupal hook without touching the core code, so all the modification is going to be in theme template.php.

/**
 * Recent comment block themed 
 * Put this function in your template.php and clear cache afterwards
 */
if (module_exists('imagecache')) {
  function phptemplate_comment_block() {
    foreach (comment_get_recent('4') as $comment) {
      $comment_object = _comment_load($comment->cid);
  		//get user details so we can get their profile picture
      $account = user_load($comment_object->uid);
  
      //check user has a picture & it exists if not show default image
      if ($account->picture && file_exists($account->picture)) {
        $picture = $account->picture;
      }
      else if (variable_get('user_picture_default', '')) {
        $picture = variable_get('user_picture_default', '');
      } 
      
      $output .= '';
      $output .= '' . $account->name .' ' . t('say') . ':';
      $output .= '' . t('@time ago', array('@time' => format_interval(time() - $comment->timestamp))) . '';
      $output .= '';
    	$output .= '' .  l(theme('imagecache', '48x48', $picture), 'user/' . $account->uid, array('html' => TRUE)) . '';
    	$output .= '';
    	$output .= '' . l($comment->subject, 'node/'. $comment->nid) . '';
    	$output .= '' . truncate_utf8($comment_object->comment, 50, $wordsafe = TRUE, $dots  = TRUE) . '';
    	$output .= '';
  	}
  	
  	return $output;
  }
}

You might notice that there are lots of pseudo div element in the code, Those pseudo div is required if you want to wrap your comment in a "speech bubble" image. Why so many pseudo element? Those element is designed to accommodate dynamic fluid width, so if you don't need those pseudo element, you can strip down the tags to simpler one.

Now enjoy a user picture in your comment block... and you can brag around that you did this without any views involved.