WordPress 获取文章的评论人数

WordPress 获取文章的评论人数
前些天,倡萌和恒创科技联合举办了一次踢楼活动(详见),活动结束后要统计此次参与踢楼的用户数量,也就是要统计提交了评论的用户数,在网上搜索了一下,发现 zwwooooo 大叔已经折腾过这个功能,试了一下,还可以用,分享过来,有需要的朋友不妨试试。
直接将下面的函数添加到当前主题的 functions.php

/* 获取文章的评论人数 by zwwooooo | zww.me */
function zfunc_comments_users( p o s t i d = 0 , postid=0, postid=0,which=0) {
KaTeX parse error: Expected 'EOF', got '&' at position 40: …'status=approve&̲type=comment&po…postid); //获取文章的所有评论
if ($comments) {
$i=0; $j=0; c o m m e n t u s e r s = a r r a y ( ) ; f o r e a c h ( commentusers=array(); foreach ( commentusers=array();foreach(comments as KaTeX parse error: Expected '}', got 'EOF' at end of input: comment) { ++i;
if ($i==1) { $commentusers[] = c o m m e n t − > c o m m e n t a u t h o r e m a i l ; + + comment->comment_author_email; ++ comment>commentauthoremail;++j; }
if ( !in_array($comment->comment_author_email, $commentusers) ) {
$commentusers[] = c o m m e n t − > c o m m e n t a u t h o r e m a i l ; + + comment->comment_author_email; ++ comment>commentauthoremail;++j;
}
}
o u t p u t = a r r a y ( output = array( output=array(j,$i);
w h i c h = ( which = ( which=(which == 0) ? 0 : 1;
return o u t p u t [ output[ output[which]; //返回评论人数
}
return 0; //没有评论返回0
}
调用方法:
1

<?php echo zfunc_comments_users($postid); ?>

参数说明:$postid 是需要获取评论人数的文章ID
一般用法:在一般主题的loop里面可以这样用:
1

<?php echo zfunc_comments_users($post->ID); ?>

PS:还可以输出评论总数,用法:
1

<?php echo zfunc_comments_users($postid, 1); ?>

本文由大资源网整理发布,转载请说明出处:https://www.dzy10.com/52443.html 免费领取VIP送建站课

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值