要想在博客首页调用所有文章的评论,请在需要的地方加入以下代码:
<aside id=comments> <h3>最新评论</h3> <?php global $wpdb; $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) 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 comment_author != "freexyz" ORDER BY comment_date DESC LIMIT 10 "; $comments = $wpdb->get_results($sql); $output = $pre_HTML; foreach ($comments as $comment) { $output .= "<dl><dt><small>$comment->comment_date</small><a href="". get_permalink($comment->ID)."#comment-".$comment->comment_ID."" title="".$comment->post_title."">".strip_tags($comment->comment_author).":</a></dt><dd>". strip_tags($comment->com_excerpt)."[...]</dd></dl>"; } $output .= $post_HTML; echo $output; ?> </aside>
在WHERE条件最后一条,我加了 AND comment_author != ‘freexyz’,表示,评论者不包括freexyz,也就是本站名称,这里改成你自己的用户名即可。如果希望现实自己的评论,就去掉这个条件。