Simple Recent Comments
或者下面的代码
复制内容到剪贴板
代码:
<?php
$comments_count = 5; // 评论数
$comments_length = 30; // 评论长度
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,
SUBSTRING(comment_content,1,$comments_length) 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 = ''
ORDER BY comment_date_gmt DESC
LIMIT $comments_count";
$comments = $wpdb->get_results($sql);
$output = "";
foreach ($comments as $comment) {
$output .= "\n<div class=\"home_recent_comment\">";
$output .= "<h4><a href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\">" . $comment->post_title . "</a></h4>";
$output .= "<div><span>" . $comment->comment_author . "</span> says : " . strip_tags($comment->com_excerpt) . "...</div>";
$output .= "</div>";
}
echo $output;
?>