descriptive
获取整个网站或某篇文章的评论数量。
Usage
<?php wp_count_comments( post_id ); ?>
parameters
$post_id
(integer) (可选) :需要统计评论数量的文章ID
默认: None
return value
返回已批准的、审核中的、垃圾评论、和已删除评论的数量。
usage example
默认使用方法
获取一个网站的评论数量。
<?php
$comments_count = wp_count_comments();
echo "整个网站中的评论:<br />";
echo "审核中: " . $comments_count->moderated . "<br />";
echo "已批准: " . $comments_count->approved . "<br />";
echo "垃圾评论: " . $comments_count->spam . "<br />";
echo "已删除评论: " . $comments_count->trash . "<br />";
echo "评论总数: " . $comments_count->total_comments . "<br />";
?>
获取某篇文章的评论数量
<?php
$comments_count = wp_count_comments( 2492 );
echo "文章 2492 <br />的评论数量:";
echo “审核中” . $comments_count->moderated . "<br />";
echo "已批准量: " . $comments_count->approved . "<br />";
echo "垃圾评论:" . $comments_count->spam . "<br />";
echo "已删除评论: " . $comments_count->trash . "<br />";
echo "评论总数: " . $comments_count->total_comments . "<br />";
?>