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