With the launch of the Blueprint site, and all the hubbub over the release of Prologue, there are now a couple of good examples of using gravatars for more than just comments. The prologue function is a little weighty to be copied to other themes, since it's built for wordpress.com, so i thought I'd share my simple method. It's almost identical to the method matt posted,
<?php $md5 = md5( strtolower(get_the_author_email()) ); $default = urlencode( get_bloginfo(template_directory) .'/icons/author.png' ); echo "<img alt='avatar' class='photo' title='photo' src='http://www.gravatar.com/avatar.php?gravatar_id=$md5&size=50&rating=X&default=$default' />"; ?>
Note that this assumes your theme has an author.png inside an icon folder. Change that line to reflect the location of your default icon, or use a blank default. If you're using Sandbox, or any other hCard-enabled wordpress theme, you can insert this inside <div class="vcard">, for added microformat-y goodness. Otherwise, you can put it anywhere you like. I've also added the same code to the top of my author.php file, inside <div class="archive-meta">.









5 Comments
Don’t forget to lowercase the email address first.
Thanks for the heads up, fixed
This is pretty slick. I am going to be using that one for sure. Just need to add a conditional to either use the avatar plugin I am using and if that doesn’t exist, use the gravatar. That should be pretty simple though.
your blog is the other example that came to mind of author avatars, but I wasn’t sure how you were doing it, so I skipped mentioning you, in case I was wrong about where your avatars came from. which I was.
The author and recent comments on my main blog are both from gravatar using http://bloggs.be/wpmu/gravatar/ and I also have both my own avatar system and gravatar in the blog comments. Some think having both avatars in my actual comments is a little much, but it is something that I am sticking with for now.
Post a Comment