Make WordPress Core

Changeset 15803


Ignore:
Timestamp:
10/14/2010 10:39:47 AM (14 years ago)
Author:
nacin
Message:

Custom post type archives. see #13818.

Location:
trunk/wp-includes
Files:
3 edited

Legend:

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

    r15779 r15803  
    922922        if ( !isset($args->rewrite['with_front']) )
    923923            $args->rewrite['with_front'] = true;
     924        if ( !isset($args->rewrite['archive']) )
     925            $args->rewrite['archive'] = false;
     926        if ( !isset($args->rewrite['feeds']) || !$args->rewrite['archive'] )
     927            $args->rewrite['feeds'] = false;
     928
    924929        if ( $args->hierarchical )
    925930            $wp_rewrite->add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
    926931        else
    927932            $wp_rewrite->add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
    928         $wp_rewrite->add_permastruct($post_type, "{$args->rewrite['slug']}/%$post_type%", $args->rewrite['with_front'], $args->permalink_epmask);
     933
     934        if ( $args->rewrite['archive'] ) {
     935            $archive_slug = $args->rewrite['archive'] === true ? $args->rewrite['slug'] : $args->rewrite['archive'];
     936            $wp_rewrite->add_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' );
     937            if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) {
     938                $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
     939                $wp_rewrite->add_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
     940                $wp_rewrite->add_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
     941            }
     942            $wp_rewrite->add_rule( "{$archive_slug}/page/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' );
     943        }
     944
     945        $wp_rewrite->add_permastruct($post_type, "{$archive_slug}/%$post_type%", $args->rewrite['with_front'], $args->permalink_epmask);
    929946    }
    930947
  • trunk/wp-includes/query.php

    r15795 r15803  
    103103 * Month, Year, Category, Author, ...
    104104 *
     105 * If the $post_types parameter is specified, this function will additionally
     106 * check if the query is for exactly one of the post types specified. If a plugin
     107 * is causing multiple post types to appear in the query, specifying a post type
     108 * will cause this check to return false.
     109 *
    105110 * @see WP_Query::is_archive()
    106111 * @since 1.5.0
    107112 * @uses $wp_query
    108113 *
     114 * @param mixed $post_types Optional. Post type or array of post types
    109115 * @return bool
    110116 */
    111 function is_archive() {
    112     global $wp_query;
    113 
    114     return $wp_query->is_archive();
     117function is_archive( $post_types = '' ) {
     118    global $wp_query;
     119
     120    return $wp_query->is_archive( $post_types );
    115121}
    116122
     
    12981304            }
    12991305
    1300             if ( '' != $qv['author_name'] ) {
     1306            if ( '' != $qv['author_name'] )
    13011307                $this->is_author = true;
    1302             }
    1303 
    1304             if ( ($this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax) )
     1308
     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 )
    13051313                $this->is_archive = true;
    13061314        }
     
    26062614     * Month, Year, Category, Author, ...
    26072615     *
     2616     * If the $post_types parameter is specified, this function will additionally
     2617     * check if the query is for exactly one of the post types specified. If a plugin
     2618     * is causing multiple post types to appear in the query, specifying a post type
     2619     * will cause this check to return false.
     2620     *
    26082621     * @since 3.1.0
    26092622     *
     2623     * @param mixed $post_types Optional. Post type or array of post types
    26102624     * @return bool
    26112625     */
    2612     function is_archive() {
    2613         return (bool) $this->is_archive;
     2626    function is_archive( $post_types ) {
     2627        if ( empty( $post_types ) || !$this->is_archive )
     2628            return (bool) $this->is_archive;
     2629
     2630        if ( ! isset( $this->posts[0] ) )
     2631            return false;
     2632
     2633        $post = $this->posts[0];
     2634
     2635        return in_array( $post->post_type, (array) $post_types );
    26142636    }
    26152637
     
    30033025    function is_singular( $post_types = '' ) {
    30043026        if ( empty( $post_types ) || !$this->is_singular )
    3005             return $this->is_singular;
     3027            return (bool) $this->is_singular;
    30063028
    30073029        $post_obj = $this->get_queried_object();
  • trunk/wp-includes/theme.php

    r15771 r15803  
    782782 */
    783783function get_archive_template() {
    784     return get_query_template('archive');
     784    $post_type = get_query_var( 'post_type' );
     785
     786    $templates = array();
     787
     788    if ( $post_type )
     789        $templates[] = "archive-{$post_type}.php";
     790    $templates[] = 'archive.php';
     791
     792    return get_query_template( 'archive', $templates );
    785793}
    786794
Note: See TracChangeset for help on using the changeset viewer.