| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Recent Comments |
|---|
| 4 | Plugin URI: http://mtdewvirus.com/code/wordpress-plugins/ |
|---|
| 5 | Description: Retrieves a list of the most recent comments. |
|---|
| 6 | Version: 1.18 |
|---|
| 7 | Author: Nick Momrik |
|---|
| 8 | Author URI: http://mtdewvirus.com/ |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | function mdv_recent_comments($no_comments = 5, $comment_lenth = 5, $before = '<li>', $after = '</li>', $show_pass_post = false, $comment_style = 0) { |
|---|
| 12 | global $wpdb; |
|---|
| 13 | $request = "SELECT ID, comment_ID, comment_content, comment_author, comment_author_url, post_title FROM $wpdb->comments LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID WHERE post_status IN ('publish','static') "; |
|---|
| 14 | if(!$show_pass_post) $request .= "AND post_password ='' "; |
|---|
| 15 | $request .= "AND comment_approved = '1' ORDER BY comment_ID DESC LIMIT $no_comments"; |
|---|
| 16 | $comments = $wpdb->get_results($request); |
|---|
| 17 | $output = ''; |
|---|
| 18 | if ($comments) { |
|---|
| 19 | foreach ($comments as $comment) { |
|---|
| 20 | $comment_author = stripslashes($comment->comment_author); |
|---|
| 21 | if ($comment_author == "") |
|---|
| 22 | $comment_author = "anonymous"; |
|---|
| 23 | $comment_content = strip_tags($comment->comment_content); |
|---|
| 24 | $comment_content = stripslashes($comment_content); |
|---|
| 25 | $words=split(" ",$comment_content); |
|---|
| 26 | $comment_excerpt = join(" ",array_slice($words,0,$comment_lenth)); |
|---|
| 27 | $permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID; |
|---|
| 28 | |
|---|
| 29 | if ($comment_style == 1) { |
|---|
| 30 | $post_title = stripslashes($comment->post_title); |
|---|
| 31 | |
|---|
| 32 | $url = $comment->comment_author_url; |
|---|
| 33 | |
|---|
| 34 | if (empty($url)) |
|---|
| 35 | $output .= $before . $comment_author . ' on ' . $post_title . '.' . $after; |
|---|
| 36 | else |
|---|
| 37 | $output .= $before . "<a href='$url' rel='external'>$comment_author</a>" . ' on ' . $post_title . '.' . $after; |
|---|
| 38 | } |
|---|
| 39 | else { |
|---|
| 40 | $output .= $before . '<strong>' . $comment_author . ':</strong> <a href="' . $permalink; |
|---|
| 41 | $output .= '" title="View the entire comment by ' . $comment_author.'">' . $comment_excerpt.'</a>' . $after; |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | $output = convert_smilies($output); |
|---|
| 45 | } else { |
|---|
| 46 | $output .= $before . "None found" . $after; |
|---|
| 47 | } |
|---|
| 48 | echo $output; |
|---|
| 49 | } |
|---|
| 50 | ?> |
|---|