<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[15803] trunk/wp-includes: Custom post type archives.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15803">15803</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-10-14 10:39:47 +0000 (Thu, 14 Oct 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Custom post type archives. see <a href="http://trac.wordpress.org/ticket/13818">#13818</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
<li><a href="#trunkwpincludesqueryphp">trunk/wp-includes/query.php</a></li>
<li><a href="#trunkwpincludesthemephp">trunk/wp-includes/theme.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (15802 => 15803)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2010-10-14 09:53:04 UTC (rev 15802)
+++ trunk/wp-includes/post.php        2010-10-14 10:39:47 UTC (rev 15803)
</span><span class="lines">@@ -921,11 +921,28 @@
</span><span class="cx">                         $args->rewrite['slug'] = $post_type;
</span><span class="cx">                 if ( !isset($args->rewrite['with_front']) )
</span><span class="cx">                         $args->rewrite['with_front'] = true;
</span><ins>+                if ( !isset($args->rewrite['archive']) )
+                        $args->rewrite['archive'] = false;
+                if ( !isset($args->rewrite['feeds']) || !$args->rewrite['archive'] )
+                        $args->rewrite['feeds'] = false;
+
</ins><span class="cx">                 if ( $args->hierarchical )
</span><span class="cx">                         $wp_rewrite->add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
</span><span class="cx">                 else
</span><span class="cx">                         $wp_rewrite->add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
</span><del>-                $wp_rewrite->add_permastruct($post_type, "{$args->rewrite['slug']}/%$post_type%", $args->rewrite['with_front'], $args->permalink_epmask);
</del><ins>+
+                if ( $args->rewrite['archive'] ) {
+                        $archive_slug = $args->rewrite['archive'] === true ? $args->rewrite['slug'] : $args->rewrite['archive'];
+                        $wp_rewrite->add_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' );
+                        if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) {
+                                $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
+                                $wp_rewrite->add_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
+                                $wp_rewrite->add_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
+                        }
+                        $wp_rewrite->add_rule( "{$archive_slug}/page/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' );
+                }
+
+                $wp_rewrite->add_permastruct($post_type, "{$archive_slug}/%$post_type%", $args->rewrite['with_front'], $args->permalink_epmask);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if ( $args->register_meta_box_cb )
</span></span></pre></div>
<a id="trunkwpincludesqueryphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/query.php (15802 => 15803)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/query.php        2010-10-14 09:53:04 UTC (rev 15802)
+++ trunk/wp-includes/query.php        2010-10-14 10:39:47 UTC (rev 15803)
</span><span class="lines">@@ -102,16 +102,22 @@
</span><span class="cx"> *
</span><span class="cx"> * Month, Year, Category, Author, ...
</span><span class="cx"> *
</span><ins>+ * 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.
+ *
</ins><span class="cx"> * @see WP_Query::is_archive()
</span><span class="cx"> * @since 1.5.0
</span><span class="cx"> * @uses $wp_query
</span><span class="cx"> *
</span><ins>+ * @param mixed $post_types Optional. Post type or array of post types
</ins><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>-function is_archive() {
</del><ins>+function is_archive( $post_types = '' ) {
</ins><span class="cx">         global $wp_query;
</span><span class="cx">
</span><del>-        return $wp_query->is_archive();
</del><ins>+        return $wp_query->is_archive( $post_types );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -1297,12 +1303,14 @@
</span><span class="cx">                                 $this->is_author = true;
</span><span class="cx">                         }
</span><span class="cx">
</span><del>-                        if ( '' != $qv['author_name'] ) {
</del><ins>+                        if ( '' != $qv['author_name'] )
</ins><span class="cx">                                 $this->is_author = true;
</span><del>-                        }
</del><span class="cx">
</span><del>-                        if ( ($this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax) )
</del><ins>+                        if ( !empty( $qv['post_type'] ) )
</ins><span class="cx">                                 $this->is_archive = true;
</span><ins>+
+                        if ( $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax )
+                                $this->is_archive = true;
</ins><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 if ( '' != $qv['feed'] )
</span><span class="lines">@@ -2605,12 +2613,26 @@
</span><span class="cx">          *
</span><span class="cx">          * Month, Year, Category, Author, ...
</span><span class="cx">          *
</span><ins>+         * 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.
+         *
</ins><span class="cx">          * @since 3.1.0
</span><span class="cx">          *
</span><ins>+         * @param mixed $post_types Optional. Post type or array of post types
</ins><span class="cx">          * @return bool
</span><span class="cx">          */
</span><del>-        function is_archive() {
-                return (bool) $this->is_archive;
</del><ins>+        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 );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /**
</span><span class="lines">@@ -3002,7 +3024,7 @@
</span><span class="cx">          */
</span><span class="cx">         function is_singular( $post_types = '' ) {
</span><span class="cx">                 if ( empty( $post_types ) || !$this->is_singular )
</span><del>-                        return $this->is_singular;
</del><ins>+                        return (bool) $this->is_singular;
</ins><span class="cx">
</span><span class="cx">                 $post_obj = $this->get_queried_object();
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/theme.php (15802 => 15803)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/theme.php        2010-10-14 09:53:04 UTC (rev 15802)
+++ trunk/wp-includes/theme.php        2010-10-14 10:39:47 UTC (rev 15803)
</span><span class="lines">@@ -781,7 +781,15 @@
</span><span class="cx"> * @return string
</span><span class="cx"> */
</span><span class="cx"> function get_archive_template() {
</span><del>-        return get_query_template('archive');
</del><ins>+        $post_type = get_query_var( 'post_type' );
+
+        $templates = array();
+
+        if ( $post_type )
+                $templates[] = "archive-{$post_type}.php";
+        $templates[] = 'archive.php';
+
+        return get_query_template( 'archive', $templates );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>
</body>
</html>