这个功能是xiu主题没有的,xiu主题有的是当前文章评论总数,这里面统计了同一个人多条评论。今天陌小雨分享的是如何获取当前文章的评论人数,这个是包括管理员自己在内的。
/* 获取文章的评论人数 by zwwooooo */
function zfunc_comments_users($postid=0,$which=0) {
$comments = get_comments('status=approve&type=comment&post_id='.$postid); //获取文章的所有评论
if ($comments) {
$i=0; $j=0; $commentusers=array();
foreach ($comments as $comment) {
++$i;
if ($i==1) { $commentusers[] = $comment->comment_author_email; ++$j; }
if ( !in_array($comment->comment_author_email, $commentusers) ) {
$commentusers[] = $comment->comment_author_email;
++$j;
}
}
$output = array($j,$i);
$which = ($which == 0) 0 : 1;
return $output[$which]; //返回评论人数
}
return 0; //没有评论返回0
}
调用方法:<?php echo zfunc_comments_users($postid); ?>
其中$postid是当前文章id。一般通过$post->ID来获取,最终调用代码就是:<?php echo zfunc_comments_users($post->ID); ?>
如何获取所有评论数呢?
<?php echo zfunc_comments_users($postid, 1); ?>






