WordPress 作者头像调用方法

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=”” />

思章老师

认准了方向,就要勇敢地走下去,十年磨一剑,我相信,只要坚持,一切都有可能。

相关日志

  1. 没有图片

    2010.06.10

    Adobe Dreamweaver CS5 新增功能

    Adobe CS5系列软件于2010年4月发…

  2. 没有图片

    2010.09.14

    WordPress 3.0 启用多站功能教程

    WordPress 3.0的多站点模式既可以…

  3. 没有图片

    2010.06.09

    Logo设计软件:AAA LOGO 3.1.0 汉化绿色版

    很多站长在设计网站的时候,一定会用到logo…

  4. 没有图片

    2010.05.08

    2009年度国外获奖Flash网站欣赏

    2009年度获奖Flash网站精品收藏,有个…

  5. 没有图片

    2010.05.31

    77个矢量按钮图标

    刚刚为大家分享一165个5种不同颜色风格的矢…

  6. 没有图片

    2010.12.08

    WordPress Conditional Tags / WordPress 条件标签使用

    在创建一款动态的 WordPress 主题过…

评论

还没有评论。