设计笔记

  • 首页
  • 作品
  • 代码
  • 随笔
  • 关于博主
    • 豆瓣书影
  • 友情链接
  • 文章归档
  • 榜上有名
  • RSS Feed
  • GitHub
  • Twitter
  • Link

喜欢这款主题

抢先体验

Typecho更简单的解决Gravatar被墙

  • Tokin
  • 2014-11-23
  • 4

enter image description here

上篇文章由于技术拙计,使用了非常痴呆的修改源文件去解决Gravatar被墙的问题,一旦程序更新,那么一切又要重新修改,相对来说还是很麻烦的,于是,更简单的方法来了。 将下方代码粘贴进入主题文件夹下的function.php内:

//自定义评论列表区域
function threadedComments($comments, $options) {
    $commentClass = '';
    if ($comments->authorId) {
        if ($comments->authorId == $comments->ownerId) {
            $commentClass .= ' comment-by-author';
        } else {
            $commentClass .= ' comment-by-user';
        }
    }

    $commentLevelClass = $comments->levels > 0 ? ' comment-child' : ' comment-parent';
?>

<li id="li-<?php $comments->theId(); ?>" class="comment-body<?php 
if ($comments->levels > 0) {
    echo ' comment-child';
    $comments->levelsAlt(' comment-level-odd', ' comment-level-even');
} else {
    echo ' comment-parent';
}
$comments->alt(' comment-odd', ' comment-even');
echo $commentClass;
?>">
    <div id="<?php $comments->theId(); ?>">
        <div class="comment-author">
            <?php
            //头像CDN by Rich
            $host = 'https://secure.gravatar.com'; //自定义头像CDN服务器
            $url = '/avatar/'; //自定义头像目录,一般保持默认即可
            $size = '32'; //自定义头像大小
            $rating = Helper::options()->commentsAvatarRating;
            $hash = md5(strtolower($comments->mail));
            $avatar = $host . $url . $hash . '?s=' . $size . '&r=' . $rating . '&d=';
            ?>
            <img class="avatar" src="<?php echo $avatar ?>" alt="<?php echo $comments->author; ?>" width="<?php echo $size ?>" height="<?php echo $size ?>" />
            <cite class="fn"><?php $comments->author(); ?></cite>
        </div>
        <div class="comment-meta">
            <a href="<?php $comments->permalink(); ?>"><?php $comments->date('Y-m-d H:i'); ?></a>
            <span class="comment-reply"><?php $comments->reply(); ?></span>
        </div>
        <?php $comments->content(); ?>
    </div>
<?php if ($comments->children) { ?>
    <div class="comment-children">
        <?php $comments->threadedComments($options); ?>
    </div>
<?php } ?>
</li>
<? }

OK,评论区域的头像问题就可以更简单的解决了,更新程序也不用重新修改源文件了。 头像源清参考:

“https://secure.gravatar.com”可以改成其它源。

多说的源:http://gravatar.duoshuo.com

七牛镜像源:http://avacdn.qiniudn.com

七牛镜像SSH源:https://dn-avacdn.qbox.me

当然自己搭建七牛镜像,或者反向代理Gravatar也是比较简单的,就不再赘述。

如果使用“评论墙”功能,请参考 >上一篇文章<

本篇文章代码来自 @Rich

© 2025 设计笔记
Theme by Wing
  • {{ item.name }}
  • {{ item.name }}