上周 @Nicky 问我如何给 Typecho 评论添加认证,其实也很简单的,分享给大家好了~

效果图:

[commentrenzheng.png]

在 functions.php 中添加以下代码

function commentApprove($widget, $email = NULL)
{
    if (empty($email)) return;

    //认证用户,再次添加认证用户邮箱
    $handsome = array(
        'xxx@126.com',
        'xxx@qq.com',
        'xxx@gmail.com'
    );

    if ($widget->authorId == $widget->ownerId) {
        echo '<b class="vip author" title="很帅的博主"></b>';
    } else if (in_array($email, $handsome)) {
        echo '<b class="vip user" title="认证贵宾"></b>';
    }
}

打开 comments.php,在适当的位置添加以下代码:

<?php commentApprove($comments, $comments->mail); ?>

建议添加在作者名称后面~

CSS美化

这是我自己使用的 CSS 喜欢的可以拿过去~!

#comments ol li .comment-author .vip {
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 2px; 
    overflow: hidden; 
    background: url(http://cdn.microhu.com/vip.png) no-repeat; 
    vertical-align: text-top;
}
#comments ol li .comment-author b.user { 
    background-position: -16px 0;
}

大家可以试试看哦,很容易的 ~