您现在的位置: 万盛学电脑网 >> 程序编程 >> CMS教程 >> 正文

wordpress获取文章评论数的方法

作者:佚名    责任编辑:admin    更新时间:2022-06-22

class="area"> wordpress获取文章评论数的方法:
<?php
$numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
if (0 < $numcomms) $numcomms = number_format($numcomms);
?>

以上代码中$numcomms即文章页的评论数,在需要输出的地方输入以下代码:

<?php echo "文章总共有 ".$numcomms." 条评论";