I just noticed that a lot of web applications are using gravatars to help personalize comments. So what are gravatars? They are meant to be a globally recognized avatar. You simply register a gravatar account, and then associate your email address with an uploaded picture. When you leave a post or comment on your favorite (or completely random) blog, the picture associated with your email address will show up next to your comment... as long as the blog has gravatars enabled.

gravatars

And that's what I'm going to show you in this post. How to enable gravatars on your WordPress account. It's surprisingly easy, since there are functions for gravatars built in the WordPress library (if you are using WordPress 2.5+).

<?php
	/**
	 * The function you'll want to use is the following.
	 *
	 * 1) 	The first parameter needs to be the users email address.
	 * 2) 	The second parameter is the size you want the picture to be.
	 * 3) 	The fourth parameter is the default image, if the user is lame
	 * 		and does not have a gravatar account.
	 * 4) 	The fifth parameter is the alternative text for the image. You know,
	 * 		the contents in the images 'alt' attribute.
	 *
	 * The 2nd, 3rd and 4th parameter are optional. If the second parameter is left
	 * blank, the default image size is 96, which is rather large.
	 **/
	echo get_avatar('users@email.com', $size='50', '../images/default.jpg', 'Gravatar Image');
?>

I know what you're (hopefully) thinking, now. How the heck do you get the commenter's email address? Well, there's a WordPress function for that, too. It's get_comment_author_email(), which was added to WordPress in 1.5.

<?php foreach ($comments as $comment) : ?>
	<li id="comment-<?php comment_ID() ?>" <?php print ($comment->user_id == 2) ? 'class="admin"' : ''; ?>>
		<div class="commentHeader">
			<strong>
				<?php comment_author_link() ?>  - <?php comment_date() ?> at <?php comment_time() ?>:
			</strong>
		</div>
		<div class="photo">
			<a title="get your avatar" href="http://www.gravatar.com">
				<?php echo get_avatar(get_comment_author_email(), $size='50'); ?>
			</a>
		</div>
		<?php comment_text() ?>
		<div class="clear"></div>
	</li>
<?php endforeach; ?>

Now you're good to go. Now go register on Gravatar and leave some comments :D