StudioPress Community Forums
  StudioPress Community Forums > Forums > General Discussion
For help and support, access to your downloads, or to manage your account please log into My StudioPress.

These forums have been set to read-only so you can browse the existing topics for any questions you may have.

For general discussion on WordPress, CSS and design (NOT for support) visit the new Community Forums.
 
 
Thread Tools Display Modes
  #1  
Old 06-21-2009, 11:02 PM
evanw evanw is offline
Registered User
Genesis Member
 
Join Date: Mar 2009
Posts: 18
Default How To: Add Gravatars to Author Pages

Recently, I wanted to make the Author page (author.php) a little more robust by replacing the static image with Wordpress Gravatars (Global avatars - http://www.gravatar.com - which are assigned to your Wordpress email address). This gives individual authors the ability to change their pictures independently without uploading any files to the server.

I also added a few conditional tags to display contact information if provided in the "Your Profile" section of Wordpress. If an author enters their website, email address, or Twitter ID, it will automatically be displayed on their profile. I have hijacked the "Yahoo Instant Messenger" field in the profile section for entering your Twitter username so keep that in mind.

Please note that these changes require Wordpress 2.8 because I used the new author meta template: http://codex.wordpress.org/Template_Tag ... uthor_meta

This code starts at approximately line 7 in author.php.

Code:
		<div class="postarea">
        
			<?php $recent = new WP_Query("showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
                
			<?php $curauth = (get_query_var('author_name')) ? get_userdatabylogin(get_query_var('author_name')) : get_userdata(intval(get_query_var('author'))); ?>
			<h5><?php echo $curauth->display_name; ?></h5>
		   
                <div class="author" id="authorinfo">
		     

		
                    

<?php if (function_exists('get_avatar')) { echo get_avatar(get_the_author_meta('user_email', $curauth->ID), '80'); }?>

                    

                    <?php echo $curauth->description; ?></p>
					


					<?php if (get_the_author_meta('yim', $curauth->ID)) { ?>
					

Twitter 
					<?php } ?>
					


					<?php if (get_the_author_meta('user_url', $curauth->ID)) { ?>
					| Web 
					<?php } ?>			

 
					<?php if (get_the_author_meta('user_email', $curauth->ID)) { ?>
					| Email</p>
					<?php } ?>							
					
                </div>
<div style="clear:both;"></div>
You'll also want to add this code to your style.css file to handle the Gravatar image.

Code:
#authorinfo img {
	margin:0px 10px 13px 0px;
	padding:2px;
	float:left;
	border:1px solid #C0C0C0;
}
Please let me know if you have any questions! You can view this code in action here.
__________________
Evan Wondrasek
  #2  
Old 06-22-2009, 09:55 AM
Craig Tuller's Avatar
Craig Tuller Craig Tuller is offline
Registered User
Pro Plus Member
 
Join Date: Sep 2008
Location: Raleigh, NC
Posts: 7,698
Default Re: How To: Add Gravatars to Author Pages

nice share!
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Gravatars? Robert Palmer General Discussion 4 03-23-2010 07:16 PM
Using author photos that are not gravatars jnor General Discussion 2 01-07-2010 12:11 AM
Blog Post Author Gravatars lfaber General Discussion 9 08-15-2009 08:35 AM
Gravatars dugeasy General Discussion 1 02-18-2009 10:03 PM


All times are GMT -5. The time now is 08:11 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.