is_comment_feed()
云策文档标注
概述
is_comment_feed() 是一个 WordPress 条件标签函数,用于检查当前查询是否为评论订阅源。它依赖于全局 $wp_query 对象,并在查询未运行时返回 false 并触发警告。
关键要点
- 函数返回布尔值,指示查询是否为评论订阅源。
- 必须在查询运行后使用,否则会调用 _doing_it_wrong() 并返回 false。
- 内部调用 $wp_query->is_comment_feed() 方法实现功能。
代码示例
function is_comment_feed() {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_comment_feed();
}注意事项
- 此函数自 WordPress 3.0.0 版本引入。
- 相关函数包括 WP_Query::is_comment_feed()、__() 和 _doing_it_wrong()。
- 被 wp_die() 和 get_comment_text() 等函数使用。
原文内容
Is the query for a comments feed?
Source
function is_comment_feed() {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_comment_feed();
}
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |