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. 没有图片

    2017.02.13

    Mac系统中安装和卸载 Mysql5.7.11 的方法

    本文给大家介绍Mac 安装和卸载 Mysql…

  2. 没有图片

    2010.05.30

    WordPress 3.0 RC1 正式发布

    小百度刚刚升级到WordPress 3.0 …

  3. 没有图片

    2011.01.07

    WordPress作者调用标签 wp_list_authors 使用教程

    一个多作者的WordPress博客,有时需要…

  4. 没有图片

    2010.05.23

    15个WordPress Nofollow Dofollow插件

    15个推荐的NofollowDofollow…

  5. 2015.09.02

    Adobe CC 2015 全线产品及注册激活补丁

    日前,Adobe旗下设计套件Adobe Cr…

  6. 没有图片

    2011.07.20

    XXOOYY 最新地址 你知道吗?

    经常从网上看到XXOOYY这几个字母,不知道…

评论

还没有评论。