wp count comments 统计整个网站或某篇文章中各个状态的评论数量

文 / @WordPress主题

wp_count_comments()

wp_count_comments()是一个函数,主要用来获取整个网站或某篇文章的评论数量。

使用方法

<?php wp_count_comments(post_id); ?>

参数

$post_id
(integer)(可选):需要统计评论数量的文章ID
默认:None

返回值

返回已批准的、审核中的、垃圾评论、和已删除评论的数量。

使用示例

默认使用方法

获取一个网站的评论数量。

<?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/>";
?>

以上就是wp_count_comments()函数的使用方法和示例,通过该函数,可以快速获取网站或文章的评论数量,并进行相应的处理。

添加UTHEME为好友
扫码添加UTHEME微信为好友
· 分享WordPress相关技术文章,主题上新与优惠动态早知道。
· 微信端最大WordPress社群,限时免费入群。