现在的位置: 首页Wordpress>不用插件实现具有Gravatar头像功能的最新留言

wordpress category

不用插件实现具有Gravatar头像功能的最新留言

发表于:2010年05月22日  分类:Wordpress  来源:原创   10 条评论  1,166人喜欢这篇文章 

可能大部WordPress用户为了美化主题外观,都会使用WP-RecentComments插件增强最近留言显示功能,该插件最大的特色就是可以显示留言Gravatar头像,但还是那句话:越少的使用插件,却能让使用者完全体验到主题的各项功能,才是真正好的主题!一段函数代码就能实现的功能,何必调用烦杂的插件。下面的两段函数代码就可以完全替代留言增强插件。
这两段函数代码,分别具有显示日志作者的留言和不显示作者留言功能,为 什么要去掉作者的留言呢,道理很简单,一般留言都显示在侧边,如果设置显示10条留言,正好有10位浏览者留言,而作者可能在同一时间内分别进行回复,结 果就是侧边显示的留言全部是作者自己的,不利于站长及时查看是否有新留言并回复。

代码一 :这段代码显示日志作者及浏览者的留言

<?php $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID, comment_content, comment_author_email, comment_date FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type = '' ORDER BY comment_date_gmt DESC LIMIT 10") ?>

<?php if ( $comments ) : foreach ($comments as $comment) : ?>

<li>
<div>
<?php if ( !empty( $comment->comment_author_email ) ) { $md5 = md5( $comment->comment_author_email ); echo get_avatar( $comment,35 );} ?>
</div>

<div class ="comments-author">
<?php comment_author_link() ?> Says :
</div>

<div>
<a href="<?php echo get_permalink($comment->comment_post_ID); ?>/#comment-<?php comment_ID() ?>" title=""><?php comment_excerpt() ?></a>
</div>
</li>

<?php endforeach; endif; ?>

代码二: 这段代码不显示日志作者留言,只显示浏览者的留言

<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url,comment_author_email, SUBSTRING(comment_content,1,14) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' AND user_id='0' ORDER BY comment_date_gmt DESC LIMIT 10";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
foreach ($comments as $comment) {$output .= "\n<li>".get_avatar(get_comment_author_email('comment_author_email'), 32).strip_tags($comment->comment_author).":<br />" . " <a href=\"" . get_permalink($comment->ID) ."#comment-" . $comment->comment_ID . "\" title=\"on " .$comment->post_title . "\">" . strip_tags($comment->com_excerpt)."</a></li>";}
$output .= $post_HTML;
echo $output;?>

固定链接: http://zmingcx.com/gravatar-avatar-with-the-latest-message.html | 知更鸟

不用插件实现具有Gravatar头像功能的最新留言:目前有10 条留言

  1. Boss方 说:

    用到哪里啊??
    直接添加到sidebar.php还是在侧边栏小工具新建文本工具粘贴呢?

  2. 说:

    能自己写是最好的了。。。
    插件左装一个右一个,应接不暇,看得我想要吐血,呵呵

  3. jinxuan 说:

    系统越来越大,插件越来越多。简单而短小的应用还是自己写写在function.php比较好。

  4. 网络过客 说:

    我现在租的没有为静态的主机,说要我另外租一个服务器,我现在哪里能租得起啊,一个月最低也要600元/月啊,老大你的是哪里租的啊,我的空间能跟你的租在一起吗价格怎么样!~

  5. 网络过客 说:

    那你说像我这样的新手是不是用国内空间就好了!~

给我留言

XHTML

快捷键:Ctrl+Enter

[ 可能不会回复无头像者留言,请申请Gravatar头像后再来留言,抱歉!]

留言没头像?这里教你设置头像!