V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yanleijava
V2EX  ›  程序员

Typecho · 获取访客 gravatar 头像

  •  1
     
  •   yanleijava · 2014-11-03 17:03:30 +08:00 · 4685 次点击
    这是一个创建于 3460 天前的主题,其中的信息可能已经有所发展或是发生改变。

    文章来自: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('[email protected]'); ?>
    

    效果

    原始效果
    QQ图片20141103161337.png
    使用后效果
    QQ图片20141103161335.png

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

    完整代码

    <?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头像

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3237 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 12:35 · PVG 20:35 · LAX 05:35 · JFK 08:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.