WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/15/2010 07:44:57 PM (9 years ago)
Author:
nacin
Message:

Custom post type archives, second pass. see #13818.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/query.php

    r15803 r15819  
    122122
    123123/**
     124 * Is the query for a post type archive page?
     125 *
     126 * @see WP_Query::is_post_type_archive()
     127 * @since 3.1.0
     128 * @uses $wp_query
     129 *
     130 * @param mixed $post_types Optional. Post type or array of posts types to check against.
     131 * @return bool
     132 */
     133function is_post_type_archive( $post_types = '' ) {
     134    global $wp_query;
     135
     136    return $wp_query->is_post_type_archive( $post_types );
     137}
     138   
     139/**
    124140 * Is the query for an attachment page?
    125141 *
     
    10401056     */
    10411057    var $is_posts_page = false;
     1058
     1059    /**
     1060     * Set if query is for a post type archive.
     1061     *
     1062     * @since 3.1.0
     1063     * @access public
     1064     * @var bool
     1065     */
     1066    var $is_post_type_archive = false;
    10421067
    10431068    /**
     
    10761101        $this->is_robots = false;
    10771102        $this->is_posts_page = false;
     1103        $this->is_post_type_archive = false;
    10781104    }
    10791105
     
    12351261            $this->is_single = false;
    12361262        } else {
    1237         // Look for archive queries.  Dates, categories, authors, search.
     1263        // Look for archive queries.  Dates, categories, authors, search, post type archives.
    12381264
    12391265            if ( !empty($qv['s']) ) {
     
    13071333                $this->is_author = true;
    13081334
    1309             if ( !empty( $qv['post_type'] ) )
    1310                 $this->is_archive = true;
    1311 
    1312             if ( $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax )
     1335            if ( !empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) {
     1336                $post_type_obj = get_post_type_object( $qv['post_type'] );
     1337                if ( is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['archive'] )
     1338                    $this->is_post_type_archive = true;
     1339            }
     1340
     1341            if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax )
    13131342                $this->is_archive = true;
    13141343        }
     
    26372666
    26382667    /**
     2668     * Is the query for a post type archive page?
     2669     *
     2670     * @since 3.1.0
     2671     *
     2672     * @param mixed $post_types Optional. Post type or array of posts types to check against.
     2673     * @return bool
     2674     */
     2675    function is_post_type_archive( $post_types = '' ) {
     2676        if ( empty( $post_types ) || !$this->is_post_type_archive )
     2677            return (bool) $this->is_post_type_archive;
     2678
     2679        if ( ! isset( $this->posts[0] ) )
     2680            return false;
     2681
     2682        $post = $this->posts[0];
     2683
     2684        return in_array( $post->post_type, (array) $post_types );
     2685    }
     2686
     2687    /**
    26392688     * Is the query for an attachment page?
    26402689     *
Note: See TracChangeset for help on using the changeset viewer.