I’m having similar difficulties. When placed outside of the loop, the gravatar code returns an incorrect image, but when placed inside the loop, it attaches a gravatar to each post listed for that author.
The code below is what I originally tried, which returns the incorrect gravatar.
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="content" class="narrowcolumn">
<?php
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin($author_name);
else :
$curauth = get_userdata(intval($author));
endif;
?>
<h2><?php echo $curauth->display_name; ?></h2>
<span class="alignright" style="margin-left:1em;"><?php echo get_avatar( get_the_author_email(), $size = '96' ); ?></span>
<dl>
<dt>About the author</dt>
<dd><?php echo $curauth->user_description; ?></dd>
</dl>
<h4>Posts by <?php echo $curauth->display_name; ?></h4>
<ul>
<!-- The Loop -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>">
<?php the_title(); ?></a>,
<?php the_time('d M Y'); ?> in <?php the_category('&');?>
</li>
<?php endwhile; else: ?>
<p><?php _e('No posts by this author.'); ?></p>
<?php endif; ?>
<!-- End Loop -->
</ul>
</div>
<?php get_footer(); ?>
I tried $curauth->gravatar, which I suspected would not work (and didn’t). I even downloaded the Gravatar plug-in, hoping that would allow me to place the code outside of the loop; but that failed as well.
I think with a bit of scouring of these forums I’ve managed to solve this problem. I have author gravatar images outside the loop on the author.php page followed by a list of all the author’s posts by using this code:
<?php global $authordata, $curauth;
$authordata=get_userdata(get_query_var( 'author' )); if(function_exists('get_avatar')) { echo get_avatar( get_the_author_id(), 70, "#646464" ); } ?>
<h2 class="grey"><?php echo $curauth->display_name; ?></h2>
<a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a>
<p><?php echo $curauth->user_description; ?></p>
Hope that works for you too.
Thanks SmallBiz that worked for me as well.