不用插件实现具有Gravatar头像功能的最新留言
可能大部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; ?>
代码二: 这段代码不显示日志作者留言,只显示浏览者的留言
固定链接: http://zmingcx.com/gravatar-avatar-with-the-latest-message.html | 知更鸟<?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;?>

















用到哪里啊??
直接添加到sidebar.php还是在侧边栏小工具新建文本工具粘贴呢?
热点新闻主题侧边留言的r_comments.php模板文件就是第二种
恩,热点新闻主题用这个我知道的。。
我如果在其他主要要用这个第二种,是直接在侧边栏用文本添加还是在sidebar.php里写代码啊?
文本小工具不能添加函数,需写在sidebar中,并且要配合相应的CSS
能自己写是最好的了。。。
插件左装一个右一个,应接不暇,看得我想要吐血,呵呵
系统越来越大,插件越来越多。简单而短小的应用还是自己写写在function.php比较好。
我现在租的没有为静态的主机,说要我另外租一个服务器,我现在哪里能租得起啊,一个月最低也要600元/月啊,老大你的是哪里租的啊,我的空间能跟你的租在一起吗价格怎么样!~
我用的当然是WOPUS的空间,Linode 主机,不是很贵
http://idc.wopus.org/vps
国内的空间更便宜
http://idc.wopus.org/
那你说像我这样的新手是不是用国内空间就好了!~
嗯,国内的空间速度比较快,不过域名需备案
国外的就不用了