WordPressを読む 27-8 /blog/wp-includes/query.php 8
2014/12/16
目次
- 1 /blog/wp-includes/query.php 8
- 2 WP_Query::is_post_type_archive()
- 3 WP_Query::is_attachment()
- 4 WP_Query::is_author()
- 5 WP_Query::is_category()
- 6 WP_Query::is_tag()
- 7 WP_Query::is_tax()
- 8 WP_Query::is_comments_popup()
- 9 WP_Query::is_date()
- 10 WP_Query::is_day()
- 11 WP_Query::is_feed()
- 12 WP_Query::is_comment_feed()
- 13 WP_Query::is_front_page()
- 14 WP_Query::is_home()
- 15 WP_Query::is_month()
/blog/wp-includes/query.php 8
WP_Query::is_post_type_archive()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Is the query for an existing post type archive page? * * @since 3.1.0 * * @param mixed $post_types Optional. Post type or array of posts types to check against. * @return bool */ public function is_post_type_archive( $post_types = '' ) { if ( empty( $post_types ) || ! $this->is_post_type_archive ) return (bool) $this->is_post_type_archive; $post_type = $this->get( 'post_type' ); if ( is_array( $post_type ) ) $post_type = reset( $post_type ); $post_type_object = get_post_type_object( $post_type ); return in_array( $post_type_object->name, (array) $post_types ); } |
WP_Query::is_attachment()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | /** * Is the query for an existing attachment page? * * @since 3.1.0 * * @param mixed $attachment Attachment ID, title, slug, or array of such. * @return bool */ public function is_attachment( $attachment = '' ) { if ( ! $this->is_attachment ) { return false; } if ( empty( $attachment ) ) { return true; } $attachment = (array) $attachment; $post_obj = $this->get_queried_object(); if ( in_array( $post_obj->ID, $attachment ) ) { return true; } elseif ( in_array( $post_obj->post_title, $attachment ) ) { return true; } elseif ( in_array( $post_obj->post_name, $attachment ) ) { return true; } return false; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | /** * Is the query for an existing author archive page? * * If the $author parameter is specified, this function will additionally * check if the query is for one of the authors specified. * * @since 3.1.0 * * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames * @return bool */ public function is_author( $author = '' ) { if ( !$this->is_author ) return false; if ( empty($author) ) return true; $author_obj = $this->get_queried_object(); $author = (array) $author; if ( in_array( $author_obj->ID, $author ) ) return true; elseif ( in_array( $author_obj->nickname, $author ) ) return true; elseif ( in_array( $author_obj->user_nicename, $author ) ) return true; return false; } |
WP_Query::is_category()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | /** * Is the query for an existing category archive page? * * If the $category parameter is specified, this function will additionally * check if the query is for one of the categories specified. * * @since 3.1.0 * * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs. * @return bool */ public function is_category( $category = '' ) { if ( !$this->is_category ) return false; if ( empty($category) ) return true; $cat_obj = $this->get_queried_object(); $category = (array) $category; if ( in_array( $cat_obj->term_id, $category ) ) return true; elseif ( in_array( $cat_obj->name, $category ) ) return true; elseif ( in_array( $cat_obj->slug, $category ) ) return true; return false; } |
WP_Query::is_tag()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | /** * Is the query for an existing tag archive page? * * If the $tag parameter is specified, this function will additionally * check if the query is for one of the tags specified. * * @since 3.1.0 * * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs. * @return bool */ public function is_tag( $tag = '' ) { if ( ! $this->is_tag ) return false; if ( empty( $tag ) ) return true; $tag_obj = $this->get_queried_object(); $tag = (array) $tag; if ( in_array( $tag_obj->term_id, $tag ) ) return true; elseif ( in_array( $tag_obj->name, $tag ) ) return true; elseif ( in_array( $tag_obj->slug, $tag ) ) return true; return false; } |
WP_Query::is_tax()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | /** * Is the query for an existing taxonomy archive page? * * If the $taxonomy parameter is specified, this function will additionally * check if the query is for that specific $taxonomy. * * If the $term parameter is specified in addition to the $taxonomy parameter, * this function will additionally check if the query is for one of the terms * specified. * * @since 3.1.0 * * @param mixed $taxonomy Optional. Taxonomy slug or slugs. * @param mixed $term. Optional. Term ID, name, slug or array of Term IDs, names, and slugs. * @return bool */ public function is_tax( $taxonomy = '', $term = '' ) { global $wp_taxonomies; if ( !$this->is_tax ) return false; if ( empty( $taxonomy ) ) return true; $queried_object = $this->get_queried_object(); $tax_array = array_intersect( array_keys( $wp_taxonomies ), (array) $taxonomy ); $term_array = (array) $term; // Check that the taxonomy matches. if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ) ) ) return false; // Only a Taxonomy provided. if ( empty( $term ) ) return true; return isset( $queried_object->term_id ) && count( array_intersect( array( $queried_object->term_id, $queried_object->name, $queried_object->slug ), $term_array ) ); } |
WP_Query::is_comments_popup()
1 2 3 4 5 6 7 8 9 10 | /** * Whether the current URL is within the comments popup window. * * @since 3.1.0 * * @return bool */ public function is_comments_popup() { return (bool) $this->is_comments_popup; } |
WP_Query::is_date()
1 2 3 4 5 6 7 8 9 10 | /** * Is the query for an existing date archive? * * @since 3.1.0 * * @return bool */ public function is_date() { return (bool) $this->is_date; } |
WP_Query::is_day()
1 2 3 4 5 6 7 8 9 10 | /** * Is the query for an existing day archive? * * @since 3.1.0 * * @return bool */ public function is_day() { return (bool) $this->is_day; } |
WP_Query::is_feed()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /** * Is the query for a feed? * * @since 3.1.0 * * @param string|array $feeds Optional feed types to check. * @return bool */ public function is_feed( $feeds = '' ) { if ( empty( $feeds ) || ! $this->is_feed ) return (bool) $this->is_feed; $qv = $this->get( 'feed' ); if ( 'feed' == $qv ) $qv = get_default_feed(); return in_array( $qv, (array) $feeds ); } |
WP_Query::is_comment_feed()
1 2 3 4 5 6 7 8 9 10 | /** * Is the query for a comments feed? * * @since 3.1.0 * * @return bool */ public function is_comment_feed() { return (bool) $this->is_comment_feed; } |
WP_Query::is_front_page()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | /** * Is the query for the front page of the site? * * This is for what is displayed at your site's main URL. * * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'. * * If you set a static page for the front page of your site, this function will return * true when viewing that page. * * Otherwise the same as @see WP_Query::is_home() * * @since 3.1.0 * @uses is_home() * @uses get_option() * * @return bool True, if front of site. */ public function is_front_page() { // most likely case if ( 'posts' == get_option( 'show_on_front') && $this->is_home() ) return true; elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) ) return true; else return false; } |
WP_Query::is_home()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Is the query for the blog homepage? * * This is the page which shows the time based blog content of your site. * * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'. * * If you set a static page for the front page of your site, this function will return * true only on the page you set as the "Posts page". * * @see WP_Query::is_front_page() * * @since 3.1.0 * * @return bool True if blog view homepage. */ public function is_home() { return (bool) $this->is_home; } |
WP_Query::is_month()
1 2 3 4 5 6 7 8 9 10 | /** * Is the query for an existing month archive? * * @since 3.1.0 * * @return bool */ public function is_month() { return (bool) $this->is_month; } |