is_attachment() - WordPress 函数参考中文文档

返回介绍

is_attachment()

发布于 2017-09-11 字数2558 浏览 869 评论 0

is_attachment( int|string|array|object $attachment = '' )

Is the query for an existing attachment page?


描述


参数

$attachment

(int|string|array|object)
(Optional)
Attachment ID, title, slug, or array of such.

Default value: ”


返回值

(bool)


源代码

File: wp-includes/query.php

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 );
}

更新日志

Version 描述
2.0.0 Introduced.

相关函数

Uses

  • wp-includes/l10n.php:
    __()
  • wp-includes/class-wp-query.php:
    WP_Query::is_attachment()
  • wp-includes/functions.php:
    _doing_it_wrong()

Used By

  • wp-includes/embed.php:
    wp_embed_excerpt_attachment()
  • wp-includes/link-template.php:
    get_adjacent_post_link()
  • wp-includes/link-template.php:
    get_adjacent_post_rel_link()
  • wp-includes/link-template.php:
    adjacent_posts_rel_link_wp_head()
  • wp-includes/link-template.php:
    get_boundary_post()
  • wp-includes/post-template.php:
    wp_list_pages()
  • wp-includes/post-template.php:
    get_post_class()
  • wp-includes/post-template.php:
    get_body_class()
  • wp-includes/canonical.php:
    redirect_canonical()
  • Show 4 more used by
    Hide more used by


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Basic Example

    
    <?php
    if ( is_attachment() ) {
    	// show adv.

    ?>

上一篇:is_archived()

下一篇:is_author()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!