More fun with author photos

Just because I've been playing with this, and someone else will surely find it useful...

I like the Author Image plugin because it allows users to add their image directly to their profile in WP admin, rather than sending them off to Gravatar to sign up there. However, the plugin's a bit limited as to what you can output: it generates a whole img src with an attached CSS class, so if you want to use it in different sizes throughout your blog (e.g. a little clickable thumbnail linking the larger version of the photo), that's impossible to do.

So I wrote a bit of PHP to go and get the image file generated by Author Image and give me the filename to do stuff with (this only works within the Loop, btw.):

<?
if ($image = glob(ABSPATH . 'wp-content/authors/' . get_the_author_meta('user_login') . '-*.*')){
$image = current($image); }
else { $image = false; }
if ($image) {
$image_url = get_bloginfo('url') . stristr($image, '/wp-content');
echo "<img class=\"author-thumb\" width=\"40\" src=\"" . $image_url . "\" />";
}
else {
// put stuff here that you want to do if there isn't an image for this author
}
?>

Share this post:
  • email
  • del.icio.us
  • Facebook
  • FriendFeed
  • LinkedIn
  • StumbleUpon
  • Tumblr
  • Twitter

Tags: ,

Posted by Sue on June 28, 2009 in Plugins, WordPress.

One comment to "More fun with author photos"

  1. Hamid Toussi wrote:

    Thanks for the code, appreciated

Leave a Reply