menu HCG_Sky's Blog
more_vert
chevron_right 首页 » 教程,随笔 » Typecho将Gravatar头像改为QQ头像
Typecho将Gravatar头像改为QQ头像
2020-05-02 | 教程,随笔 | 1 条评论 | 3304 次阅读 | 370字

博客默认的Gravatar太煞风景?那就换了它!

前言

相信大部分做过网站的朋友都知道,Gravatar是一个全球性的头像设置平台
除中国以外大部分网站都是调用的此平台头像,但因为我们伟大的祖国有一般人射不穿的城墙
所以用这个头像平台的用户很少,导致大部分使用此头像平台的网站
评论区总会有很多Gravatar的官方默认头像


定位文件

↓找到主题下的comments.php文件,查找关键字gravatar↓
↓我们会发现下面一段语句↓
<?php $comments->gravatar('40', ''); ?>

↓果断删掉↓

↓改成如下代码↓
<span itemprop="image">
<?php $number=$comments->mail; echo '<img src="https://q2.qlogo.cn/headimg_dl? bs='.$number.'&dst_uin='.$number.'&dst_uin='.$number.'&;dst_uin='.$number.'&spec=100&url_enc=0&referer=bu_interface&term_type=PC" width="46px" height="46px" style="border-radius: 50%;float: left;margin-top: 0px;margin-right: 10px;margin-bottom:-2px">'; ?>
</span>

总结

即用第二条语句把原来的替换掉即可

效果

更新

在通常情况下,当用户输入了QQ邮箱,我们的头像才会调用为QQ头像。但是假如用户使用的是163邮箱或者是其它邮箱,那么头像肯定会显示失败。那么该怎样解决这个问题呢?其实也很简单,我们放个if判断语句就行了。先判断输入的邮箱是不是QQ邮箱,如果是调用QQ邮箱,如果不是则调用Gravatar头像或者其他的静态头像,或者随机头像即可。

更新代码

代码如下
<span itemprop="image">
<?php $number=$comments->mail;
if(preg_match('|^[1-9]\d{4,11}@qq\.com$|i',$number)){
echo '<img src="https://q2.qlogo.cn/headimg_dl? bs='.$number.'&dst_uin='.$number.'&dst_uin='.$number.'&;dst_uin='.$number.'&spec=100&url_enc=0&referer=bu_interface&term_type=PC" width="46px" height="46px" style="border-radius: 50%;float: left;margin-top: 0px;margin-right: 10px;margin-bottom:-2px">'; 
}
else
{
echo '<img src="​https://bing.ioliu.cn/v1/rand?w=1920&h=1080" width="46px" height="46px" style="border-radius: 50%;float: left;margin-top: 0px;margin-right: 10px;margin-bottom:-2px">';
}
?>
</span>

整理的随机图片API接口

速度: ★★★★★

功能: 返回Bing的随机图片

地址:

https://uploadbeta.com/api/pictures/random/?key=BingEverydayWallpaperPicture

速度: ★★★★☆

功能: 来自github的项目https://github.com/xCss/bing

地址:

https://bing.ioliu.cn/v1/rand (返回随机图片)
https://bing.ioliu.cn/v1/rand?w=1920&h=1080 (指定大小)

文章目录
发表评论
已有 1 条评论
textsms
account_circle
email
link


    Hacther
    Hacther     Windows 10 /    MicroSoft Edge
    May 2nd, 2020 at 07:46 pm

    witty牛逼就完事了~

arrow_back 上一篇
arrow_forward 下一篇
七牛云 腾讯云 阿里云 百度统计 TrustAsia 安全签章 MySSL 安全签章