ScriptyGoddess' plugin, which is based HEAVILY on http://mtdewvirus.com/wp-hacks/ recent comments plugin) Version: 1.0 Author: The Barry Bittwister Cabal Author URI: http://singlenesia.com */ class drt_recent_comments { function get_posts($no_posts = 5, $start_at = 0, $show_pass_post = false) { global $wpdb, $tablecomments, $tableposts; if (!isset($tablecomments)) $tableoptions = $wpdb->comments; if (!isset($tableposts)) $tableoptions = $wpdb->posts; $request = "SELECT ID, post_title, comment_author, comment_date, comment_id, comment_post_ID"; $request .= " FROM $tableposts INNER JOIN $tablecomments ON $tableposts.ID = $tablecomments.comment_post_ID WHERE comment_approved = '1' AND post_status = 'publish' "; if(!$show_pass_post) $request .= "AND post_password ='' "; $request .= "ORDER BY comment_date DESC"; $resultset = $wpdb->get_results($request); if ($resultset === false) die( "Error"); $output = ""; $posts = array(); $counter = 0; while ($data = $resultset[$counter]) { $counter++; $post_id = $data->ID; $post_title = $data->post_title; $comment_author = $data->comment_author; $comment_date = $data->comment_date; $comment_id = $data->comment_id; $comment_post_id = $data->comment_post_ID; $post = $posts[$post_id]; $comment_timestamp = strtotime($comment_date); if (!$post) { $posts[$post_id] = array('comment_date' => $comment_date, 'comment_author' => $comment_author, 'comment_count' => 1, 'post_title' => $post_title, 'post_id' => $post_id, 'comment_id' => $comment_id, 'comment_post_ID' => $comment_post_id); } else { $posts[$post_id]['comment_count']++; if ( $comment_timestamp > strtotime( $post['comment_date'] ) ) { $posts[$post_id] = array('comment_date' => $comment_date, 'comment_author' => $comment_author, 'comment_count' => $posts[$post_id]['comment_count'], 'post_title' => $post_title, 'post_id' => $post_id, 'comment_id' => $comment_id, 'comment_post_ID' => $comment_post_id); } } } $posts = array_values($posts); sort($posts); $posts = array_reverse($posts); $posts = array_slice( $posts, $start_at, $no_posts ); return( $posts ); } function show_posts ($no_posts = 5, $start_at = 0, $show_count = true, $show_last = true, $show_flat = false, $show_pass_post = false) { // $no_posts = The number of posts with recent comments to show // $start_at = What recent post # to start at ($no_posts = 5, $start_at = 5 displays five posts, beginning with the 6th most recently commented on) // $show_count = TRUE to show the # of comments for the post // $how_last = TRUE to show the date of the most recent comment // $show_flat = TRUE to show the entire entry as one
  • line // $show_pass_post = TRUE to count password-protected posts. $comments = drt_recent_comments::get_posts( $no_posts, $start_at, $show_pass_post ); $output = ''; if ($comments) { foreach ($comments as $comment) { $link = get_permalink($comment['comment_post_ID']); $title = stripslashes($comment['post_title']); $count = $comment['comment_count']; if( class_exists( "drt_disco" ) ) { $d = drt_disco::mysql2disco( $comment['comment_date'] ); $strs = $d->Disco(); $date = $strs['season']."/".$strs['day']."/".$strs['year']; } else { $d = $comment['comment_date']; $date = date( "m/d/Y", mktime( substr( $d,11,2 ), substr( $d,14,2 ), substr( $d,17,2 ), substr( $d,5,2 ), substr( $d,8,2 ), substr( $d,0,4 ) ) ); } if( $show_flat ) { $output .= "
  • $title
    "; if( $show_count || $show_last ) { $output .= "
    "; if( $show_count ) { $output .= "$count msg"; if( $count != 1 ) $output .= "s"; if( $show_last ) $output .= ", "; } if( $show_last ) $output .= "last: $date"; $output .= "
    "; } $output .= "
  • "; } else { $output .= '
  • '.$title.''; if( $show_count || $show_last ) { $output .= ""; } $output .= "
  • "; } } echo $output; } } } ?>