欢迎您光临自学哈网,只为分享网络知识教程,供大家学习参考!

「自学哈网」wordpress获取文章评论数及人数

作者 : 自学哈 本文共541个字,预计阅读时间需要2分钟 2022-11-26 共99人阅读
也想出现在这里? 联系我们
/**

* 获取文章的评论人数 
*$postid:文章id
*$which:返回类型(0或1)为0时返回评论人数,为1时返回评论条数
*/
function count_comments($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
}
本站声明:
本站所有资源来源于网络,分享目的仅供大家学习和交流!如若本站内容侵犯了原著者的合法权益,可联系邮箱976157886@qq.com进行删除。
自学哈专注于免费提供最新的分享知识、网络教程、网络技术的资源分享平台,好资源不私藏,大家一起分享!

自学哈网 » 「自学哈网」wordpress获取文章评论数及人数
也想出现在这里? 联系我们
© 2022 Theme by - 自学哈网 & WordPress Theme. All rights reserved 浙ICP备2022016594号