WordPress.org

Make WordPress Core


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

Custom post type archives. see #13818.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.