<!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>[13032] trunk/wp-includes: Look for single-.php templates.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13032">13032</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-02-08 22:05:05 +0000 (Mon, 08 Feb 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Look for single-.php templates. Add single- class to get_body_class(). Props ptahdunbar. see <a href="http://trac.wordpress.org/ticket/12105">#12105</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesposttemplatephp">trunk/wp-includes/post-template.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="trunkwpincludesposttemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post-template.php (13031 => 13032)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post-template.php        2010-02-08 21:02:08 UTC (rev 13031)
+++ trunk/wp-includes/post-template.php        2010-02-08 22:05:05 UTC (rev 13032)
</span><span class="lines">@@ -392,14 +392,17 @@
</span><span class="cx">                 $classes[] = 'error404';
</span><span class="cx">
</span><span class="cx">         if ( is_single() ) {
</span><del>-                $postID = $wp_query->get_queried_object_id();
</del><ins>+                $post_id = $wp_query->get_queried_object_id();
+                $post = $wp_query->get_queried_object();
</ins><span class="cx">
</span><del>-                $classes[] = 'single postid-' . $postID;
</del><ins>+                $classes[] = 'single';
+                $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
+                $classes[] = 'postid-' . $post_id;
</ins><span class="cx">
</span><span class="cx">                 if ( is_attachment() ) {
</span><del>-                        $mime_type = get_post_mime_type($postID);
</del><ins>+                        $mime_type = get_post_mime_type($post_id);
</ins><span class="cx">                         $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
</span><del>-                        $classes[] = 'attachmentid-' . $postID;
</del><ins>+                        $classes[] = 'attachmentid-' . $post_id;
</ins><span class="cx">                         $classes[] = 'attachment-' . str_replace($mime_prefix, '', $mime_type);
</span><span class="cx">                 }
</span><span class="cx">         } elseif ( is_archive() ) {
</span><span class="lines">@@ -419,13 +422,13 @@
</span><span class="cx">         } elseif ( is_page() ) {
</span><span class="cx">                 $classes[] = 'page';
</span><span class="cx">
</span><del>-                $pageID = $wp_query->get_queried_object_id();
</del><ins>+                $page_id = $wp_query->get_queried_object_id();
</ins><span class="cx">
</span><del>-                $post = get_page($pageID);
</del><ins>+                $post = get_page($page_id);
</ins><span class="cx">
</span><del>-                $classes[] = 'page-id-' . $pageID;
</del><ins>+                $classes[] = 'page-id-' . $page_id;
</ins><span class="cx">
</span><del>-                if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status = 'publish' LIMIT 1", $pageID) ) )
</del><ins>+                if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status = 'publish' LIMIT 1", $page_id) ) )
</ins><span class="cx">                         $classes[] = 'page-parent';
</span><span class="cx">
</span><span class="cx">                 if ( $post->post_parent ) {
</span><span class="lines">@@ -434,7 +437,7 @@
</span><span class="cx">                 }
</span><span class="cx">                 if ( is_page_template() ) {
</span><span class="cx">                         $classes[] = 'page-template';
</span><del>-                        $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $pageID, '_wp_page_template', true ) ), '' );
</del><ins>+                        $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $page_id, '_wp_page_template', true ) ), '' );
</ins><span class="cx">                 }
</span><span class="cx">         } elseif ( is_search() ) {
</span><span class="cx">                 if ( !empty($wp_query->posts) )
</span></span></pre></div>
<a id="trunkwpincludesqueryphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/query.php (13031 => 13032)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/query.php        2010-02-08 21:02:08 UTC (rev 13031)
+++ trunk/wp-includes/query.php        2010-02-08 22:05:05 UTC (rev 13032)
</span><span class="lines">@@ -2549,28 +2549,27 @@
</span><span class="cx">          * @return object
</span><span class="cx">          */
</span><span class="cx">         function get_queried_object() {
</span><del>-                if (isset($this->queried_object)) {
</del><ins>+                if ( isset($this->queried_object) )
</ins><span class="cx">                         return $this->queried_object;
</span><del>-                }
</del><span class="cx">
</span><span class="cx">                 $this->queried_object = NULL;
</span><span class="cx">                 $this->queried_object_id = 0;
</span><span class="cx">
</span><del>-                if ($this->is_category) {
</del><ins>+                if ( $this->is_category ) {
</ins><span class="cx">                         $cat = $this->get('cat');
</span><span class="cx">                         $category = &get_category($cat);
</span><span class="cx">                         if ( is_wp_error( $category ) )
</span><span class="cx">                                 return NULL;
</span><span class="cx">                         $this->queried_object = &$category;
</span><span class="cx">                         $this->queried_object_id = (int) $cat;
</span><del>-                } else if ($this->is_tag) {
</del><ins>+                } elseif ( $this->is_tag ) {
</ins><span class="cx">                         $tag_id = $this->get('tag_id');
</span><span class="cx">                         $tag = &get_term($tag_id, 'post_tag');
</span><span class="cx">                         if ( is_wp_error( $tag ) )
</span><span class="cx">                                 return NULL;
</span><span class="cx">                         $this->queried_object = &$tag;
</span><span class="cx">                         $this->queried_object_id = (int) $tag_id;
</span><del>-                } else if ($this->is_tax) {
</del><ins>+                } elseif ( $this->is_tax ) {
</ins><span class="cx">                         $tax = $this->get('taxonomy');
</span><span class="cx">                         $slug = $this->get('term');
</span><span class="cx">                         $term = &get_terms($tax, array('slug'=>$slug));
</span><span class="lines">@@ -2579,16 +2578,16 @@
</span><span class="cx">                         $term = $term[0];
</span><span class="cx">                         $this->queried_object = $term;
</span><span class="cx">                         $this->queried_object_id = $term->term_id;
</span><del>-                } else if ($this->is_posts_page) {
</del><ins>+                } elseif ( $this->is_posts_page ) {
</ins><span class="cx">                         $this->queried_object = & get_page(get_option('page_for_posts'));
</span><span class="cx">                         $this->queried_object_id = (int) $this->queried_object->ID;
</span><del>-                } else if ($this->is_single) {
</del><ins>+                } elseif ( $this->is_single ) {
</ins><span class="cx">                         $this->queried_object = $this->post;
</span><span class="cx">                         $this->queried_object_id = (int) $this->post->ID;
</span><del>-                } else if ($this->is_page) {
</del><ins>+                } elseif ( $this->is_page ) {
</ins><span class="cx">                         $this->queried_object = $this->post;
</span><span class="cx">                         $this->queried_object_id = (int) $this->post->ID;
</span><del>-                } else if ($this->is_author) {
</del><ins>+                } elseif ( $this->is_author ) {
</ins><span class="cx">                         $author_id = (int) $this->get('author');
</span><span class="cx">                         $author = get_userdata($author_id);
</span><span class="cx">                         $this->queried_object = $author;
</span></span></pre></div>
<a id="trunkwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/theme.php (13031 => 13032)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/theme.php        2010-02-08 21:02:08 UTC (rev 13031)
+++ trunk/wp-includes/theme.php        2010-02-08 22:05:05 UTC (rev 13032)
</span><span class="lines">@@ -860,7 +860,7 @@
</span><span class="cx"> function get_page_template() {
</span><span class="cx">         global $wp_query;
</span><span class="cx">
</span><del>-        $id = (int) $wp_query->post->ID;
</del><ins>+        $id = (int) $wp_query->get_queried_object_id();
</ins><span class="cx">         $template = get_post_meta($id, '_wp_page_template', true);
</span><span class="cx">         $pagename = get_query_var('pagename');
</span><span class="cx">
</span><span class="lines">@@ -909,7 +909,11 @@
</span><span class="cx"> * @return string
</span><span class="cx"> */
</span><span class="cx"> function get_single_template() {
</span><del>-        return get_query_template('single');
</del><ins>+        global $wp_query;
+
+        $object = $wp_query->get_queried_object();
+        $templates = array('single-' . $object->post_type . '.php', 'single.php');
+        return apply_filters('single_template', locate_template($templates));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -974,11 +978,11 @@
</span><span class="cx"> * @return string The template filename if one is located.
</span><span class="cx"> */
</span><span class="cx"> function locate_template($template_names, $load = false) {
</span><del>-        if (!is_array($template_names))
</del><ins>+        if ( !is_array($template_names) )
</ins><span class="cx">                 return '';
</span><span class="cx">
</span><span class="cx">         $located = '';
</span><del>-        foreach($template_names as $template_name) {
</del><ins>+        foreach ( $template_names as $template_name ) {
</ins><span class="cx">                 if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
</span><span class="cx">                         $located = STYLESHEETPATH . '/' . $template_name;
</span><span class="cx">                         break;
</span><span class="lines">@@ -988,7 +992,7 @@
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if ($load && '' != $located)
</del><ins>+        if ( $load && '' != $located )
</ins><span class="cx">                 load_template($located);
</span><span class="cx">
</span><span class="cx">         return $located;
</span></span></pre>
</div>
</div>
</body>
</html>