is_attachment

函数
is_attachment ( $attachment = '' )
参数
  • (int|string|int[]|string[]) $attachment Optional. Attachment ID, title, slug, or array of such to check against. Default empty.
    Required:
    Default: (empty)
返回值
  • (bool) Whether the query is for an existing attachment page.
定义位置
相关方法
is_local_attachmentwp_insert_attachmentwp_attachment_is_fix_attachment_linksprepend_attachment
引入
2.0.0
弃用
-

is_attachment: 这个函数检查当前页面是否是一个附件页。一个附件页是一个显示单个媒体项目的页面,如图片或视频。如果当前页面是一个附件页,它返回true,否则返回false。

确定查询是否是针对现有的附件页。

关于这个和类似的主题函数的更多信息,请查看《主题开发者手册》中的{@link Conditional Tags}文章。

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.0' );
		return false;
	}

	return $wp_query->is_attachment( $attachment );
}

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-05 15:32:55

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: