Display Recent Comments


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. global $wpdb;
  3. $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
  4. comment_post_ID, comment_author, comment_date_gmt, comment_approved,
  5. comment_type,comment_author_url,
  6. SUBSTRING(comment_content,1,30) AS com_excerpt
  7. FROM $wpdb->comments
  8. LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
  9. $wpdb->posts.ID)
  10. WHERE comment_approved = '1' AND comment_type = '' AND
  11. post_password = ''
  12. ORDER BY comment_date_gmt DESC
  13. LIMIT 10";
  14. $comments = $wpdb->get_results($sql);
  15. $output = $pre_HTML;
  16. $output .= "\n<ul>";
  17. foreach ($comments as $comment) {
  18. $output .= "\n<li>".strip_tags($comment->comment_author)
  19. .":" . "<a href=\"" . get_permalink($comment->ID) .
  20. "#comment-" . $comment->comment_ID . "\" title=\"on " .
  21. $comment->post_title . "\">" . strip_tags($comment->com_excerpt)
  22. ."</a></li>";
  23. }
  24. $output .= "\n</ul>";
  25. $output .= $post_HTML;
  26. echo $output;?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.