因为国内Gavatar被墙,很多时候镜像源又不是那么好使还不如改成使用QQ头像来的稳妥,而且评论默认留邮箱使得更加完美。

步骤

1.将下面的代码写入 主题模板funtions.php 文件当中

//获取Gravatar头像 QQ邮箱取用qq头像
function getGravatar($email, $s = 96, $d = 'mp', $r = 'g', $img = false, $atts = array())
{
preg_match_all('/((\d)*)@qq.com/', $email, $vai);
if (empty($vai['1']['0'])) {
    $url = 'https://www.gravatar.com/avatar/';
    $url .= md5(strtolower(trim($email)));
    $url .= "?s=$s&d=$d&r=$r";
    if ($img) {
        $url = '<img src="' . $url . '"';
        foreach ($atts as $key => $val)
        $url .= ' ' . $key . '="' . $val . '"';
        $url .= ' />';
    }
}else{
    $url = 'https://q2.qlogo.cn/headimg_dl?dst_uin='.$vai['1']['0'].'&spec=100';
     }
return  $url;
}

2.再将下面的代码复制到需要放头像的页面,通常是 comments.php

<?php $email=$comments->mail; $imgUrl = getGravatar($email);echo '<img src="'.$imgUrl.'" width="45px" height="45px" style="border-radius: 50%;" >'; ?>
最后修改:2022 年 05 月 31 日
如果觉得我的文章对你有用,请随意赞赏