comments WHERE comment_type ='' AND comment_approved = '1'"; $have_comment_post_ids = $wpdb->get_results($q); foreach ($have_comment_post_ids as $have_comment_post_id){ $q = "SELECT comment_author,user_id FROM $wpdb->comments WHERE comment_type ='' AND comment_approved = '1' AND comment_post_id = $have_comment_post_id->comment_post_id order by comment_date limit 1"; $first_comment = $wpdb->get_results($q); $top_first_commentors_exclude = $top_first_commentors_options["exclude"]; if(!$top_first_commentors_exclude){ array_push($first_commentors,$first_comment[0] -> comment_author); }else{ $top_first_commentors_exclude = explode(",",$top_first_commentors_exclude); if(!in_array($first_comment[0] -> user_id,$top_first_commentors_exclude)){ array_push($first_commentors,$first_comment[0] -> comment_author); } } } $first_commentors = (array_count_values ($first_commentors)); arsort($first_commentors); $first_commentors_author = array_keys($first_commentors); $top_first_commentors = array(); $top_first_commentors_number = $top_first_commentors_options["number"]; if(!$top_first_commentors_number) $top_first_commentors_number = 3; $top_first_commentors_titles = $top_first_commentors_options["titles"]; if($top_first_commentors_titles) $top_first_commentors_titles = explode(",",$top_first_commentors_titles); for($i=0; $i<$top_first_commentors_number; $i++){ $q = "SELECT comment_author_url FROM $wpdb->comments WHERE comment_type ='' AND user_id = 0 AND comment_approved = '1' AND comment_author_url !='' AND comment_author = '$first_commentors_author[$i]' limit 1"; $first_comment_url = $wpdb->get_results($q); $top_first_commentors_title = $top_first_commentors_titles[$i]; if($top_first_commentors_title) $top_first_commentors_title .= " : "; if($first_comment_url){ $top_first_commentors[$i] = $top_first_commentors_title . '' . $first_commentors_author[$i] . '(' . $first_commentors["$first_commentors_author[$i]"].')'; } else { $top_first_commentors[$i] = $top_first_commentors_titles[$i] .$first_commentors_author[$i] . '('.$first_commentors["$first_commentors_author[$i]"] . ')'; } } wp_cache_set("top_first_commentors", $top_first_commentors, "tfc", 36000); return $top_first_commentors; } function get_top_first_commentors(){ $output = ""; $output .= ''; return $output; } function top_first_commentors(){ $output = get_top_first_commentors(); echo $output; } function widget_sidebar_top_first_commentors() { if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') ) return; function widget_top_first_commentors($args) { extract($args); echo $before_widget; $top_first_commentors_options = get_option('widget_top_first_commentors'); $title = $top_first_commentors_options['title']; if ( empty($title) ) $title = 'Top First Commentors'; echo $before_title . $title . $after_title; $output = get_top_first_commentors(); echo $output; echo $after_widget; } register_sidebar_widget('Top First Commentors', 'widget_top_first_commentors'); function widget_top_first_commentors_options() { $top_first_commentors_options = $new_top_first_commentors_options = get_option('widget_top_first_commentors'); if ( $_POST["top_first_commentors_submit"] ) { $new_top_first_commentors_options['title'] = strip_tags(stripslashes($_POST["top_first_commentors_title"])); if ( $top_first_commentors_options != $new_top_first_commentors_options ) { $top_first_commentors_options = $new_top_first_commentors_options; update_option('widget_top_first_commentors', $top_first_commentors_options); } } $title = attribute_escape($top_first_commentors_options['title']); ?>

$_POST['top_first_commentors_exclude_option'], "number" => $_POST['top_first_commentors_number_option'], "titles" => $_POST['top_first_commentors_titles_option'] ); if ($top_first_commentors_saved != $top_first_commentors) if(!update_option("top_first_commentors",$top_first_commentors)) $message='Update failed'; update_top_first_commentors(); echo '

'. $message . '

'; } $top_first_commentors_options = get_option("top_first_commentors"); ?>

Top First Commentors

Exclude: " /> Exclude the users, input the user id, seprate with comma.
Number: " /> Set the number of top first commentors.
Title: " /> Set the title for every top first commentor, for example: First,Second,Third