mw_comments, returns the comments for a given post, or else a count of how many there are, depending on the parameter you pass it. The second function, mw_trackbacks, does the same for trackbacks and pingbacks. The counting capability makes it easy to do MT-style comment/trackback counts on a post (i.e., "C:1 T:3").
Version: 1.0.1
Date: 24 July 2004
Author: Eric A. Meyer
Author URI: http://meyerweb.com/
*/
/*
Version history:
1.0.1 (24 July 2004)
- Added 'comment_approved' check to prevent unapproved comments from being counted/returned.
1.0 (10 May 2004)
- Initial release.
*/
function mw_comments($param = '') {
global $wpdb, $tablecomments, $post;
$comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_post_ID = $post->ID AND comment_content NOT LIKE '%%' AND comment_content NOT LIKE '%%' AND comment_approved = '1'");
if ('count' == $param) {
echo count($comments);
} else {
return $comments;
}
}
function mw_trackbacks($param = '') {
global $wpdb, $tablecomments;
$trackbacks = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_content LIKE ('%%') AND comment_approved = '1'");
if ('count' == $param) {
echo count($trackbacks);
} else {
return $trackbacks;
}
}
?>