Post Avatars in Entry Header in Genesis

This places the post avatar in the entry header of feature posts (if you're using the grid loop plugin) and on single post pages. It also allows for co-author plus support, showing a different image when there is more than one author.

<?php
/**
* Places the author avatar next to the entry header for feature posts, not teaser posts.
* Includes support for co-authors plus plugin
* Replace the BLOGLOGURL with an actual url to an alternate image
*
* @author Joshua David Nelson, joshuadnelson.com
**/
add_action( 'genesis_entry_header', 'jdn_author_post_avatar', 1 ); // using a priority of 1 to insure it is first, before title
function jdn_author_post_avatar() {
if( is_home() || is_single() ){ // only on blog page and single post pages, not on archives
if( in_array( 'feature', get_post_class( '', get_the_ID() ), true ) || is_single() ) { // only on posts with a 'feature' class
if( !function_exists( 'get_coauthors' ) || ( function_exists( 'get_coauthors' ) && 1 == count( get_coauthors( get_the_id() ) ) ) ) { // if using co-authors and a single author, or if not using co-authors
if( get_query_var( 'author_name' ) ) {
$curauth = get_userdatabylogin( get_query_var( 'author_name' ) );
} else {
$curauth = get_userdata( get_query_var( 'author' ) );
}
?>
<div class="author_grav">
<? echo "<a href=\"/author/" . get_the_author_meta( 'user_login' ) . "\">" . get_avatar( get_the_author_meta( 'email' ), '50' ) . "</a>"; ?>
</div>
<?php
} else { // otherwise, let's use the blog logo
?>
<div class="author_grav">
<a href="/members/"><img src="BLOGLOGOURL" width="50" height="50" class="avatar" /></a>
</div>
<?php
}
}
}
}

Source: https://gist.github.com/joshuadavidnelson/9065384

Tags: , , ,