is_trackback()
云策文档标注
概述
is_trackback() 是一个 WordPress 条件标签函数,用于判断当前查询是否为 trackback 端点调用。它依赖于全局 $wp_query 对象,在查询运行前调用会返回 false 并触发错误提示。
关键要点
- 函数返回布尔值,表示查询是否为 trackback 端点调用。
- 必须在查询运行后使用,否则会触发 _doing_it_wrong() 错误并返回 false。
- 内部调用 WP_Query::is_trackback() 方法来实现功能。
代码示例
function is_trackback() {
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_trackback();
}注意事项
- 此函数属于条件标签,建议参考主题开发者手册中的 Conditional Tags 文章了解更多信息。
- 相关函数包括 WP_Query::is_trackback()、__() 和 _doing_it_wrong()。
- 自 WordPress 1.5.0 版本引入。
原文内容
Determines whether the query is for a trackback endpoint call.
Description
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Source
function is_trackback() {
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_trackback();
}
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |