WordPress 作者头像调用方法详细解释
简介:最近在设计UEDCMS 主题时发现WordPress 作者头像调用方法有很多种, 下面讲讲具体的使用方法:
1. 在文章页面调用作者头像, 非常简单, 一句话就可以实现:
<?php echo get_avatar( get_the_author_email(), 60 ); ?>
2. 在作者列表页面调用作者头像...
最近在设计UEDCMS 主题时发现WordPress 作者头像调用方法有很多种, 下面讲讲具体的使用方法:
1. 在文章页面调用作者头像, 非常简单, 一句话就可以实现:
<?php echo get_avatar( get_the_author_email(), 60 ); ?>
2. 在作者列表页面调用作者头像, 方法和页面有点不同, 不过也不麻烦, 具体代码如下:
在author-template.php模板里添加下面的代码即可:
$author_email = get_the_author_email(); $avatar = get_avatar($author->ID ,32);
然后将
$link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' .$name. '</a>';
改成:
$link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' .$avatar . '</a>';
即可.
3. 作者页面的头像调用又有点特别, 需要做特别处理, 具体实现方法如下:
<?php // Determine which gravatar to use for the user $GLOBALS['defaultgravatar'] = $template_path . '/images/avatar.gif'; $email = $curauth->user_email; $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5($email). "&default=".urlencode($GLOBALS['defaultgravatar'] )."&size=60"; ?> <img src="<?php echo $grav_url; ?>" width="60" height="60" alt="" />
好了,今天就讲这么多WordPress 作者头像的调用方法,以后有更好的方法再和大家分享.

已经知道怎么弄了。。谢谢你的教材
下面是大前端主题的读者墙问题,下面得创建个avatar的文件夹,由于VPS的问题,不知道无法保存头像图片,所以,我想调用默认的头像,该如何修改?
function dtheme_page_readers($outer,$timer,$limit){
global $wpdb;
$counts = $wpdb->get_results(“select count(comment_author) as cnt, comment_author, comment_author_url, comment_author_email from (select * from $wpdb->comments left outer join $wpdb->posts on ($wpdb->posts.id=$wpdb->comments.comment_post_id) where comment_date > date_sub( now(), interval $timer month ) and user_id=’0′ and comment_author != ‘”.$outer.”‘ and post_password=” and comment_approved=’1′ and comment_type=”) as tempcmt group by comment_author order by cnt desc limit $limit”);
foreach ($counts as $count) {
$avatar_url = get_bloginfo(‘wpurl’) . ‘/avatar/’ . md5(strtolower($count->comment_author_email));
$c_url = $count->comment_author_url;
if ($c_url == ”) $c_url = ”;
$type .= ‘‘ . $count->comment_author . ‘+’. $count->cnt . ‘‘.substr( $c_url , 7 ).’‘;
}
echo $type;
}
?>
如何修改成调用默认的头像。谢谢
还是这篇文章帮了忙!
呵呵 好