<?php comments_number();?>
这个 WordPress 功能计算帖子的评论数量;当没有评论时,它会返回文本“NO comment”。这会导致我的布局出现问题,所以我希望它显示 0 零。我怎么做?据我所知,我必须制作一个过滤器,但我不知道该使用哪个钩子。
另外,我们怎么知道这是正确的钩子?一些关于如何解决这个问题的技巧会更有帮助,这样我下次可以自己创建一个过滤器。
您可以设置零,如:
comments_number('0', '1', '%');
文档:http ://codex.wordpress.org/Function_Reference/comments_number
或者您可以get_comments_number
将评论总数的返回值仅用作数值
$num = get_comments_number();
if ( $num == 0) {
// something to do
}
文档:http ://codex.wordpress.org/Template_Tags/get_comments_number
根据http://codex.wordpress.org/Function_Reference/comments_number你可以做
comments_number('0 Comments', '1 Comment', '% Comments');