描述:
判断当前页面是否为一个附件页面“图片或文件”。
用法:
<?php is_attachment(); ?>
参数:
None
示例:
<?php
if ( is_attachment() ) {
// show adv. #1
} else {
// show adv. #2
}
?>
源文件:
/**
* 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 );
}