以前并不知道如何获取文章的评论数量,只是知道通过get_comments_number函数来解决问题,不过问题也比较多,根据官方显示,这个函数是获取文章所有评论数量: [wp url="https://developer.wordpress.org/reference/functions/get_comments_number/" unique_number="wp_65f3de16d3f24919894c707ef2f75726"]
但是我需要的仅仅是经过审核的也就是通过的评论数量,那么可能就需要别的函数解决了。
如果你正好也有这样的问题。那么可以考虑使用下面的函数: [wp url="https://developer.wordpress.org/reference/functions/wp_count_comments/" unique_number="wp_f53fd9ae71e24494a746eb6c10488b32"]
根据官方的解释,通过这个函数我们可以获取指定状态的评论数量,下面是一个来自官方的例子:
"; echo "Comments in moderation: " . $comments_count->moderated . "
"; echo "Comments approved: " . $comments_count->approved . "
"; echo "Comments in Spam: " . $comments_count->spam . "
"; echo "Comments in Trash: " . $comments_count->trash . "
"; echo "Total Comments: " . $comments_count->total_comments . "
"; ?>
这个函数还是很好用的,至少不用像之前的函数那么麻烦了,感兴趣的朋友可以自己去尝试一下看看效果。