利用非插件方法实现Wordpress侧边栏最新评论带avatar头像结果

[摘要]通过利用最新评论插件WP-RecentComments可以很容易地实现wordpress博客侧边栏最新评论带avatar头像结果,但对付代码流博主来说,给WP添加多一个插件都是一种罪过,所以在有高人连续研究出非插件WordPress的各类能力,同样,侧栏最新评论带头像也可以利用“非插件”来搞定。

  通过利用最新评论插件WP-RecentComments可以很容易地实现wordpress博客侧边栏最新评论带avatar头像结果,但对付代码流博主来说,给WP添加多一个插件都是一种罪过,所以在有高人连续研究出非插件WordPress的各类能力,同样,侧栏最新评论带头像也可以利用“非插件”来搞定。

WordPress下载:WordPress 非插件侧栏带头像最新评论:

  在主题模板的侧边栏模板sidebar.php适当位置添加以下代码:

<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,25) 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 comment_author != '板凳' AND post_password = '' 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'), 18). " <a href=http://down.chinaz.com/\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=http://down.chinaz.com/\"" . $comment->post_title . " 上的评论\">". strip_tags($comment->comment_author) .": ". strip_tags($comment->com_excerpt) ."</a></li>";
}
$output .= $post_HTML;
$output = convert_smilies($output);
echo $output;
?>

  个中的“板凳”换本钱身的博主作者名,主要是为了限制输出博主的最新评论。然后生存文件即可。

本文转自:博客吧

分享到

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/10674.html