is_attachment()
is_attachment( int|string|int[]|string[] $attachment = ” )
确定查询是否针对现有附件页。
Determines whether the query is for an existing attachment page.
说明(Description)
有关此主题函数和类似主题函数的更多信息,请参阅主题开发人员手册中的条件标记文章。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$attachment | (int | string | int[] | string[]) | 可选 | 要检查的附件ID、标题、段塞或其数组。 |
返回(Return)
(bool)
源码(Source)
/** * Is the query for an existing attachment page? * * @since 2.0.0 * * @global WP_Query $wp_query * * @param int|string|array|object $attachment Attachment ID, title, slug, or array of such. * @return bool */ function is_attachment( $attachment = '' ) { 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' ); return false; } return $wp_query->is_attachment( $attachment ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
2.0.0 | wp-includes/query.php:205 | 9 | 3 |
笔记(Notes)
基本示例
is_attachment() 为WP2原创文章,链接:https://www.wp2.cn/functions/is_attachment/