have_comments()判断当前文章/页面是否有评论

目录

描述

Determines whether there are any Comments to loop over or not.

have_comments() 描述

用法

This function relies upon the global $wp_query object to be set - this is usually the case from within The Loop.

Warning: this function will always return "false" until after comments_template has been called. If you need to check for comments before calling comments_template, use get_comments_number instead.

<?php $have_comments have_comments(); ?>

have_comments() 用法

参数

n/a

have_comments() 参数

返回值

(bool) 

true if the current query has comments available, false otherwise.

have_comments() 返回值

示例

Example based on Twentyten's comments.php template: Comments title (and more) is displayed only when comments are available:

have_comments() 示例

注意

  • 使用到 global: (object) $wp_query to determine if comments are available (via have_comments method).

have_comments() 注意

历史

添加于 版本: 2.2.0

have_comments() 历史

源文件

have_comments() 函数的代码位于 wp-includes/query.php.

have_comments() 源文件

相关