在WordPress开发中,我们常常会在循环外获取文章评论总数,此函数就是用来做这的。
php_sliver_functions:站长多年来积累的一套代码片段库,码云地址:
描述
在WordPress开发中,我们常常会在循环外获取文章评论总数,此函数就是用来做这的。
开始
function sliverCommentsConut($post_id){
$args = array(
'post_id' => $post_id,
'count' => true
);
$count=get_comments( $args );
return $count;
}
使用
将以上代码放在主题的函数文件(functions.php),前台调用时传入文章id即可