Typecho · 获取访客 gravatar 头像

2014-11-03 17:03:30 +08:00
 yanleijava

文章来自:Typecho · 获取访客gravatar头像

前言

找了下typecho的相关文章,并没有找到获取老访客的头像的文章,那就只能自己动手实现了。

实现方式

  1. 得到访客在网站记住的邮箱、用户、网址等信息
  2. 根据邮箱地址转换成Gravatar的头像地址

获取用户邮箱

typecho获取邮箱地址为:

<?php $this->remember('mail',true) ?>

Gravatar头像地址

直接通过URL获取Gravatar头像地址

<img src="http://www.gravatar.com/avatar/md5(<?php $this->remember('mail',true) ?>)?s=32" >;

进阶

由于使用了gravatar头像缓存插件GravatarCache,这让头像显示变的简单

因为GravatarCache中实现了根据邮箱获取头像的函数

<?php GravatarCache::getGravatarCache('example@domain.com'); ?>

效果

原始效果

使用后效果

实际效果可以参考本站评论!

完整代码

<?php if($this->remember('author',true) != "" && $this->remember('mail',true) != ""){ ?>
                <p class="title welcome" style="text-align:center;">                  
                  <a class="edit_author" onclick="$('.welcome').hide()&&$('.author_info').show();return false;">
                      <img style="display: block;margin: 35px auto 8px auto;float: center;" class="avatar" src="<?php echo GravatarCache::getGravatarCache($this->remember('mail',true),false,50); ?>" alt="QQ" width="50" height="50">
                      <?php $this->remember('author'); ?>
                  </a>
                </p>
                <div class="author_info" style="display:none;">
                <?php } ?>
            <p>
                <label for="author" class="required"><?php _e('称呼'); ?></label>
                <input type="text" name="author" id="author" class="text" value="<?php $this->remember('author'); ?>" />
            </p>
            <p>
                <label for="mail"<?php if ($this->options->commentsRequireMail): ?> class="required"<?php endif; ?>><?php _e('邮箱'); ?></label>
                <input type="email" name="mail" id="mail" class="text" value="<?php $this->remember('mail'); ?>" />
            </p>
            <p>
                <label for="url"<?php if ($this->options->commentsRequireURL): ?> class="required"<?php endif; ?>><?php _e('网站'); ?></label>
                <input type="url" name="url" id="url" class="text" placeholder="<?php _e('http://example.com'); ?>" value="<?php $this->remember('url'); ?>" />
            </p>
                <?php if($this->remember('author',true) != "" && $this->remember('mail',true) != ""){ ?>
                    </div>
                <?php } ?>

文章来自:Typecho · 获取访客gravatar头像

4693 次点击
所在节点    程序员
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/143657

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX