<!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-&gt;rewrite['slug'] = $post_type;
</span><span class="cx">                 if ( !isset($args-&gt;rewrite['with_front']) )
</span><span class="cx">                         $args-&gt;rewrite['with_front'] = true;
</span><ins>+                if ( !isset($args-&gt;rewrite['archive']) )
+                        $args-&gt;rewrite['archive'] = false;
+                if ( !isset($args-&gt;rewrite['feeds']) || !$args-&gt;rewrite['archive'] )
+                        $args-&gt;rewrite['feeds'] = false;
+
</ins><span class="cx">                 if ( $args-&gt;hierarchical )
</span><span class="cx">                         $wp_rewrite-&gt;add_rewrite_tag(&quot;%$post_type%&quot;, '(.+?)', $args-&gt;query_var ? &quot;{$args-&gt;query_var}=&quot; : &quot;post_type=$post_type&amp;name=&quot;);
</span><span class="cx">                 else
</span><span class="cx">                         $wp_rewrite-&gt;add_rewrite_tag(&quot;%$post_type%&quot;, '([^/]+)', $args-&gt;query_var ? &quot;{$args-&gt;query_var}=&quot; : &quot;post_type=$post_type&amp;name=&quot;);
</span><del>-                $wp_rewrite-&gt;add_permastruct($post_type, &quot;{$args-&gt;rewrite['slug']}/%$post_type%&quot;, $args-&gt;rewrite['with_front'], $args-&gt;permalink_epmask);
</del><ins>+
+                if ( $args-&gt;rewrite['archive'] ) {
+                        $archive_slug = $args-&gt;rewrite['archive'] === true ? $args-&gt;rewrite['slug'] : $args-&gt;rewrite['archive'];
+                        $wp_rewrite-&gt;add_rule( &quot;{$archive_slug}/?$&quot;, &quot;index.php?post_type=$post_type&quot;, 'top' );
+                        if ( $args-&gt;rewrite['feeds'] &amp;&amp; $wp_rewrite-&gt;feeds ) {
+                                $feeds = '(' . trim( implode( '|', $wp_rewrite-&gt;feeds ) ) . ')';
+                                $wp_rewrite-&gt;add_rule( &quot;{$archive_slug}/feed/$feeds/?$&quot;, &quot;index.php?post_type=$post_type&quot; . '&amp;feed=$matches[1]', 'top' );
+                                $wp_rewrite-&gt;add_rule( &quot;{$archive_slug}/$feeds/?$&quot;, &quot;index.php?post_type=$post_type&quot; . '&amp;feed=$matches[1]', 'top' );
+                        }
+                        $wp_rewrite-&gt;add_rule( &quot;{$archive_slug}/page/([0-9]{1,})/?$&quot;, &quot;index.php?post_type=$post_type&quot; . '&amp;paged=$matches[1]', 'top' );
+                }
+
+                $wp_rewrite-&gt;add_permastruct($post_type, &quot;{$archive_slug}/%$post_type%&quot;, $args-&gt;rewrite['with_front'], $args-&gt;permalink_epmask);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if ( $args-&gt;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-&gt;is_archive();
</del><ins>+        return $wp_query-&gt;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-&gt;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-&gt;is_author = true;
</span><del>-                        }
</del><span class="cx"> 
</span><del>-                        if ( ($this-&gt;is_date || $this-&gt;is_author || $this-&gt;is_category || $this-&gt;is_tag || $this-&gt;is_tax) )
</del><ins>+                        if ( !empty( $qv['post_type'] ) )
</ins><span class="cx">                                 $this-&gt;is_archive = true;
</span><ins>+
+                        if ( $this-&gt;is_date || $this-&gt;is_author || $this-&gt;is_category || $this-&gt;is_tag || $this-&gt;is_tax )
+                                $this-&gt;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-&gt;is_archive;
</del><ins>+        function is_archive( $post_types ) {
+                if ( empty( $post_types ) || !$this-&gt;is_archive )
+                        return (bool) $this-&gt;is_archive;
+
+                if ( ! isset( $this-&gt;posts[0] ) )
+                        return false;
+
+                $post = $this-&gt;posts[0];
+
+                return in_array( $post-&gt;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-&gt;is_singular )
</span><del>-                        return $this-&gt;is_singular;
</del><ins>+                        return (bool) $this-&gt;is_singular;
</ins><span class="cx"> 
</span><span class="cx">                 $post_obj = $this-&gt;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[] = &quot;archive-{$post_type}.php&quot;;
+        $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>