在WordPress博客上,顯示每個(gè)留言者的留言總數(shù),效果如下:
方法很簡(jiǎn)單,在funtions.php文件里加上下面的代碼:
function commentCountAuthor(){ $oneText = 'One comment';
$moreText = '% comments'; global $wpdb; $result = $wpdb->get_var('
SELECT
COUNT(comment_ID)
FROM
'.$wpdb->comments.'
WHERE
comment_author_email = "'.get_comment_author_email().'"'
); if($result == 1): echo str_replace('%', $result, $oneText); elseif($result > 1): echo str_replace('%', $result, $moreText); endif;}
然后在評(píng)論loop里調(diào)用這個(gè)函數(shù)就Ok了。
commentCountAuthor();