Comment Count 'id' can be the ID of the post you want to know the number of comments for. If you pass an id of 0, then it will count the number of comments for the current post that 'the loop' is working on. If you allow it to be default or set it to 'all', it will count the total number of comments in all posts. 'echo' should be TRUE if you want the routine to echo the count. drt_utils::last_comment(id,echo): returns the date of the most recent comment made for the given post. The parameters work like drt_comment::num() (except for 'all') drt_utils::getpostid(nicename); returns the post ID if the page with the given nicename. drt_utils::getNumPostsWithComments(); Returns the umber of posts in the database that have at least one comment. */ class drt_utils { function num_comments($postid = 'all', $echo = false) { global $wpdb, $id, $tablecomments; $request = "SELECT COUNT(*) FROM $tablecomments WHERE comment_approved = '1'"; if (!$postid) $request .= " AND comment_post_ID=$id"; elseif( $postid != 'all' ) $request .= " AND comment_post_ID=$postid"; $result = $wpdb->get_var($request); if( $echo ) echo $result; return $result; } function last_comment($postid = '', $echo = false) { global $wpdb, $id, $tablecomments; $request = "SELECT comment_date FROM $tablecomments WHERE comment_approved = '1'"; if (!$postid) $request .= " AND comment_post_ID=$id"; else $request .= " AND comment_post_ID=$postid"; $request .= " ORDER BY comment_date DESC LIMIT 1"; $result = $wpdb->get_var($request); if( $echo ) echo $result; return $result; } function getpostID( $pagename ) { global $wpdb, $tableposts; $post = $wpdb->get_row("SELECT ID FROM $tableposts WHERE post_name = '$pagename'"); return( $post->ID ); } function getNumPostsWithComments() { global $wpdb, $tableposts, $tablecomments; $output = count( $wpdb->get_results( "SELECT COUNT(*) FROM wp_posts LEFT JOIN wp_comments ON wp_posts.ID=wp_comments.comment_post_ID WHERE wp_comments.comment_post_ID AND post_status = 'publish' GROUP BY ID" ) ); return( $output ); } } ?>