调用wordpress网友评论方法最简洁的方法
使用wordpress的朋友应该都知道,wordpres自带的最新评论功能,显示的是评论所在的日志,而我们经常希望显示出来的是评论的内容。有很多插件都可以解决这个问题,不过如果不用插件,速度上肯定是有优势的。下面WP管理员之家来教大家wordpress调用网友评论的最简洁方法
- <?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, 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 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 class=\"new\">" . $comment->comment_author . " 评论道:<br /> <a href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=\"". $comment->comment_author. ":" . $comment->post_title . "\">" . strip_tags($comment->com_excerpt) ."</a></li>";
- }
- $output .= $post_HTML;
- echo $output;
- ?>
感谢分享,谢谢站长!!