Custom post type archives. see #13818.

git-svn-id: https://develop.svn.wordpress.org/trunk@15803 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin
2010-10-14 10:39:47 +00:00
parent 2e864d29ad
commit 86ab32a196
3 changed files with 57 additions and 10 deletions

View File

@@ -102,16 +102,22 @@ function wp_reset_postdata() {
*
* Month, Year, Category, Author, ...
*
* If the $post_types parameter is specified, this function will additionally
* check if the query is for exactly one of the post types specified. If a plugin
* is causing multiple post types to appear in the query, specifying a post type
* will cause this check to return false.
*
* @see WP_Query::is_archive()
* @since 1.5.0
* @uses $wp_query
*
* @param mixed $post_types Optional. Post type or array of post types
* @return bool
*/
function is_archive() {
function is_archive( $post_types = '' ) {
global $wp_query;
return $wp_query->is_archive();
return $wp_query->is_archive( $post_types );
}
/**
@@ -1297,11 +1303,13 @@ class WP_Query extends WP_Object_Query {
$this->is_author = true;
}
if ( '' != $qv['author_name'] ) {
if ( '' != $qv['author_name'] )
$this->is_author = true;
}
if ( ($this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax) )
if ( !empty( $qv['post_type'] ) )
$this->is_archive = true;
if ( $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax )
$this->is_archive = true;
}
@@ -2605,12 +2613,26 @@ class WP_Query extends WP_Object_Query {
*
* Month, Year, Category, Author, ...
*
* If the $post_types parameter is specified, this function will additionally
* check if the query is for exactly one of the post types specified. If a plugin
* is causing multiple post types to appear in the query, specifying a post type
* will cause this check to return false.
*
* @since 3.1.0
*
* @param mixed $post_types Optional. Post type or array of post types
* @return bool
*/
function is_archive() {
return (bool) $this->is_archive;
function is_archive( $post_types ) {
if ( empty( $post_types ) || !$this->is_archive )
return (bool) $this->is_archive;
if ( ! isset( $this->posts[0] ) )
return false;
$post = $this->posts[0];
return in_array( $post->post_type, (array) $post_types );
}
/**
@@ -3002,7 +3024,7 @@ class WP_Query extends WP_Object_Query {
*/
function is_singular( $post_types = '' ) {
if ( empty( $post_types ) || !$this->is_singular )
return $this->is_singular;
return (bool) $this->is_singular;
$post_obj = $this->get_queried_object();