带Gravatar头像无插件评论

写自 by Licream

标签: wordpress

grav
图片对比我也没发现什么特别的,结果就是省了一个插件.呵呵.免插件实现的评论信息.,我不会PS图片.这图做的好丑..发出来了各位就好好接受哈~

在网上又找到了一个好方法,一直用的wp-recentcomments插件也该下岗了。几经周折,慢慢的给调出来了,呵呵!不过ajax翻页功能没了。像这种华而不实的功能我是没怎么用,没了也不碍事。我先把方法贴上来,分享及以后备用。。。

复制下面的的代码到主题functions.php文件最下面的?>前面。

//最新评论函数
//下行no_comments =是调用最新评论的条数
function get_recent_comments($no_comments = 5, $before = '<li> ', $after = '<div class="clear"></div></li>', $show_pass_post = false) {
//最新评论涉及的相关数据库查询字段,针对原版我添加了post_title, comment_author_email 两个字段,分别是日志标题字段和评论者email字段
//下面的comment_author是过滤不显示评论的评论者昵称,你可以改为你自己
	global $wpdb, $tablecomments, $tableposts;
	$request = "SELECT ID, comment_ID, comment_content, post_title, comment_author_email, comment_author FROM $tableposts, $tablecomments WHERE
$tableposts.ID=$tablecomments.comment_post_ID AND (post_status = 'publish' AND comment_author !='popdo' OR post_status = 'static') AND comment_type = ''";

if(!$show_pass_post) { $request .= "AND post_password ='' "; }

    $request .= "AND comment_approved = '1' ORDER BY $tablecomments.comment_date DESC LIMIT

$no_comments";
    $comments = $wpdb->get_results($request);
    $output = '';
    foreach ($comments as $comment) {
       $comment_author = stripslashes($comment->comment_author);
//下行设置评论截断的字数,使用mb_strimwidth精准统一截断中英文字数
       $comment_excerpt = mb_strimwidth(strip_tags(apply_filters('the_comment', $comment->comment_content)), 0, 25,"...");
       $permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;
//下行是最新评论调用显示相关,我插入了调用gravatar头像函数和日志标题函数,并且修改了这部分的输出布局。
      $output .= $before . ' ' . get_avatar($comment, 32) . '<a href="' . $permalink . '" title="标题: ' . $comment->post_title  . '">' . $comment_author . '</a>' .'<p>'. $comment_excerpt . '</p>'.'' . $after;
       }
       echo $output;
}

原作者是在中文wordpress工具箱里精简下来的代码。
上面的弄好后,再去添加一个样式

.avatar{
                float:left;
                margin:1px 5px 0px 0px;
                padding:0px 0px 0px 0px;
                width:32px;
        }
        .avatar-right{
                float:right;
                line-height:16px;
                margin:0px 5px 0px 0px;
                padding:0px 0px 0px 0px;
                width:220px;
        }
        .avatar-right p{
                margin:3px 0px 0px 0px;
                padding:0px 0px 0px 0px;
        }

    .clear{
                clear: both;
          height:0px;
        overflow:hidden;
        }

再到边栏文件里添加下面代码

<?php get_commentmembersstats($threshhold = 5); ?>

具体效果看我边栏评论。

30条评论 请留下你最想说的:)

  1. Ivan_Mikhailov Opera Windows 说到:

    I want to quote your post in my blog. It can?
    And you et an account on Twitter?

  2. kingchow CHINA Internet Explorer Windows 说到:

    :razz: 研究下…

  3. Licream CHINA Google Chrome Windows 说到:

    @53blog: 欢迎常来哈

  4. 53blog CHINA Internet Explorer Windows 说到:

    有我的头像。。嘿嘿

  5. Jutoy CHINA Google Chrome Windows 说到:

    嗯,方法先收藏了~留着备用……
    忽然发现截图是我的BLOG,囧

  6. Licream CHINA Mozilla Firefox Windows 说到:

    @Swanche: 你的更有内涵!是种享受阿

  7. Swanche REPUBLIC OF KOREA Internet Explorer Windows 说到:

    我来了n次,很想说点什么,可是……我看不懂。。。。

  8. 90后的贼 CHINA Internet Explorer Windows 说到:

    @↘Smile,____: 这个名字好熟悉哦

  9. Licream CHINA Google Chrome Windows 说到:

    @Junan: 谢谢哦:)

  10. Junan CHINA Internet Explorer Windows 说到:

    现在这个已经很好了。

  11. Licream CHINA Google Chrome Windows 说到:

    @JohnnY: 需要帮忙不,要不我给你调调?

  12. ↘Smile,____ CHINA Internet Explorer Windows 说到:

    还是不懂、我也不是这个境界的人、不知道有什么用

  13. 仁心博客 CHINA Internet Explorer Windows 说到:

    这个很好的呢

  14. JohnnY AUSTRIA Mozilla Firefox Windows 说到:

    @Licream: 应该是添加样式和sidebar的问题。。。不知道该加在哪里,胡乱试了一下,然后侧边栏就显示不出来了

  15. Licream CHINA Mozilla Firefox Windows 说到:

    @JohnnY: 不是吧.出什么提示了没

  16. JohnnY AUSTRIA Mozilla Firefox Windows 说到:

    试了半天没成功,郁闷~~~

  17. 老七 CHINA Internet Explorer Windows 说到:

    现在这个好帅~~

  18. 卢松松 CHINA Mozilla Firefox Windows 说到:

    这次看到效果了,更整齐了

  19. hunter919 CHINA Mozilla Firefox Windows 说到:

    这个厉害了。。可惜看不懂。。哇嘎嘎

  20. Swanche REPUBLIC OF KOREA Internet Explorer Windows 说到:

    果然,不是我这个境界的人看得懂的

  21. 漠岚 CHINA Internet Explorer Windows 说到:

    呵呵!效果可以让大家注意一下哪里有变化 ,或者挂一个图啊

  22. Tangboke CHINA Internet Explorer Windows 说到:

    还是插件来得方便。

  23. Licream CHINA Mozilla Firefox Windows 说到:

    @卢松松: @最后的风筝: @53blog: @张黎:
    0 0,为了减少一个插件,效果是没有的哈.

  24. 张黎 CHINA Internet Explorer Windows 说到:

    有时间我也试试看

  25. 53blog CHINA Internet Explorer Windows 说到:

    我也没看到什么。。

  26. 最后的风筝 CHINA Mozilla Firefox Windows 说到:

    这个方法不错。。

  27. 卢松松 CHINA Mozilla Firefox Windows 说到:

    没看到的啥效果的

留下评论哦 Here's Your Chance to Be Heard!