<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Creating single post templates in WordPress</title>
	<atom:link href="http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress</link>
	<description>Life, Blogging, and WordPress</description>
	<lastBuildDate>Fri, 10 Feb 2012 12:19:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Matej Latin</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-403690</link>
		<dc:creator>Matej Latin</dc:creator>
		<pubDate>Mon, 22 Aug 2011 12:15:06 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-403690</guid>
		<description>thanks for this.. I didn&#039;t know it&#039;s so simple.. and I like it simple :)</description>
		<content:encoded><![CDATA[<p>thanks for this.. I didn&#8217;t know it&#8217;s so simple.. and I like it simple <img src='http://justintadlock.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Euge</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-380474</link>
		<dc:creator>Euge</dc:creator>
		<pubDate>Sun, 17 Jul 2011 21:06:41 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-380474</guid>
		<description>Thanks Scott for your code! But I found a problem, what about sub-sub categories? Or sub-sub-sub-sub categories? :D
This is the complete code that I added to my functions.php

&lt;pre&gt;&lt;code&gt;function pa_category_top_parent_id ($catid) {
 
 while ($catid) {
  $cat = get_category($catid); // get the object for the catid
  $catid = $cat-&gt;category_parent; // assign parent ID (if exists) to $catid
  // the while loop will continue whilst there is a $catid
  // when there is no longer a parent $catid will be NULL so we can assign our $catParent
  $catParent = $cat-&gt;cat_ID;
 }
 
return $catParent;
}


//-----------------------------------------------------------
//funcion para mostrar un single template para cada categoria
/**
* Define a constant path to our single template folder
*/
define(SINGLE_PATH, TEMPLATEPATH . &#039;/single&#039;);

/**
* Filter the single_template with our custom function
*/
add_filter(&#039;single_template&#039;, &#039;my_single_template&#039;);

/**
* Single template function which will choose our template
*/
function my_single_template($single) {
	global $wp_query, $post;

/**
	* Checks for single template by category
	* Check by category slug and ID
	*/
	foreach((array)get_the_category() as $cat) :

		
		$categoriapadre= pa_category_top_parent_id ($cat);
		
		if(file_exists(SINGLE_PATH . &#039;/single-cat-&#039; . $cat-&gt;term_id . &#039;.php&#039;))
			return SINGLE_PATH . &#039;/single-cat-&#039; . $cat-&gt;term_id . &#039;.php&#039;;
		
		elseif(file_exists(SINGLE_PATH . &#039;/single-cat-&#039; . $categoriapadre . &#039;.php&#039;))
			return SINGLE_PATH . &#039;/single-cat-&#039; . $categoriapadre . &#039;.php&#039;;	

	endforeach;
return $single;

}&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Thanks Scott for your code! But I found a problem, what about sub-sub categories? Or sub-sub-sub-sub categories? <img src='http://justintadlock.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
This is the complete code that I added to my functions.php</p>
<pre><code>function pa_category_top_parent_id ($catid) {

 while ($catid) {
  $cat = get_category($catid); // get the object for the catid
  $catid = $cat-&gt;category_parent; // assign parent ID (if exists) to $catid
  // the while loop will continue whilst there is a $catid
  // when there is no longer a parent $catid will be NULL so we can assign our $catParent
  $catParent = $cat-&gt;cat_ID;
 }

return $catParent;
}

//-----------------------------------------------------------
//funcion para mostrar un single template para cada categoria
/**
* Define a constant path to our single template folder
*/
define(SINGLE_PATH, TEMPLATEPATH . '/single');

/**
* Filter the single_template with our custom function
*/
add_filter('single_template', 'my_single_template');

/**
* Single template function which will choose our template
*/
function my_single_template($single) {
	global $wp_query, $post;

/**
	* Checks for single template by category
	* Check by category slug and ID
	*/
	foreach((array)get_the_category() as $cat) :

		$categoriapadre= pa_category_top_parent_id ($cat);

		if(file_exists(SINGLE_PATH . '/single-cat-' . $cat-&gt;term_id . '.php'))
			return SINGLE_PATH . '/single-cat-' . $cat-&gt;term_id . '.php';

		elseif(file_exists(SINGLE_PATH . '/single-cat-' . $categoriapadre . '.php'))
			return SINGLE_PATH . '/single-cat-' . $categoriapadre . '.php';	

	endforeach;
return $single;

}</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Random Joe</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-335473</link>
		<dc:creator>Random Joe</dc:creator>
		<pubDate>Tue, 03 May 2011 14:44:24 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-335473</guid>
		<description>Can you upload a theme folder that works on wordpress 3.1.2. I really need the method for checking a template by author.

Thanks</description>
		<content:encoded><![CDATA[<p>Can you upload a theme folder that works on wordpress 3.1.2. I really need the method for checking a template by author.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Random Joe</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-335460</link>
		<dc:creator>Random Joe</dc:creator>
		<pubDate>Tue, 03 May 2011 14:16:36 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-335460</guid>
		<description>does checking for author by user nicename and user ID work on wordpress 3.1.2?

I&#039;m trying to make this work on twentyten theme. I cant seem to make it work.</description>
		<content:encoded><![CDATA[<p>does checking for author by user nicename and user ID work on wordpress 3.1.2?</p>
<p>I&#8217;m trying to make this work on twentyten theme. I cant seem to make it work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skybondsor</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-321585</link>
		<dc:creator>skybondsor</dc:creator>
		<pubDate>Tue, 05 Apr 2011 00:29:25 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-321585</guid>
		<description>This is still great over two years later!  Thanks for posting it.</description>
		<content:encoded><![CDATA[<p>This is still great over two years later!  Thanks for posting it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christopher Wulff</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-321154</link>
		<dc:creator>Christopher Wulff</dc:creator>
		<pubDate>Mon, 04 Apr 2011 04:48:04 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-321154</guid>
		<description>Got my question answered on  WordPress StackExchange here: http://wordpress.stackexchange.com/questions/13837/conflict-in-function-to-allow-single-post-template-based-on-category

Here&#039;s the code:

&lt;pre&gt;&lt;code&gt;/* Define a constant path to our single template folder */
define(SINGLE_PATH, TEMPLATEPATH . &#039;/single&#039;);

/* Filter the single_template with our custom function*/
add_filter(&#039;single_template&#039;, &#039;my_single_template&#039;);

/* Single template function which will choose our template*/
function my_single_template($single) {
    global $wp_query, $post;

/* Checks for single template by post type */
if ($post-&gt;post_type == &quot;POST TYPE NAME&quot;){
    if(file_exists(SINGLE_PATH . &#039;/single-&#039; . $post-&gt;post_type . &#039;.php&#039;))
        return SINGLE_PATH . &#039;/single-&#039; . $post-&gt;post_type . &#039;.php&#039;;
}

/* Checks for single template by category. Check by category slug and ID */
foreach((array)get_the_category() as $cat) :

    if(file_exists(SINGLE_PATH . &#039;/single-cat-&#039; . $cat-&gt;slug . &#039;.php&#039;))
        return SINGLE_PATH . &#039;/single-cat-&#039; . $cat-&gt;slug . &#039;.php&#039;;

    elseif(file_exists(SINGLE_PATH . &#039;/single-cat-&#039; . $cat-&gt;term_id . &#039;.php&#039;))
        return SINGLE_PATH . &#039;/single-cat-&#039; . $cat-&gt;term_id . &#039;.php&#039;;

endforeach;

/*Checks for default single post files within the single folder */
if(file_exists(SINGLE_PATH . &#039;/single.php&#039;))
    return SINGLE_PATH . &#039;/single.php&#039;;

elseif(file_exists(SINGLE_PATH . &#039;/default.php&#039;))
    return SINGLE_PATH . &#039;/default.php&#039;;

return $single; 
}&lt;/code&gt;&lt;/pre&gt;

and just replace &quot;POST TYPE NAME&quot; with your custom post type name.</description>
		<content:encoded><![CDATA[<p>Got my question answered on  WordPress StackExchange here: <a href="http://wordpress.stackexchange.com/questions/13837/conflict-in-function-to-allow-single-post-template-based-on-category" rel="nofollow">http://wordpress.stackexchange.com/questions/13837/conflict-in-function-to-allow-single-post-template-based-on-category</a></p>
<p>Here&#8217;s the code:</p>
<pre><code>/* Define a constant path to our single template folder */
define(SINGLE_PATH, TEMPLATEPATH . '/single');

/* Filter the single_template with our custom function*/
add_filter('single_template', 'my_single_template');

/* Single template function which will choose our template*/
function my_single_template($single) {
    global $wp_query, $post;

/* Checks for single template by post type */
if ($post-&gt;post_type == "POST TYPE NAME"){
    if(file_exists(SINGLE_PATH . '/single-' . $post-&gt;post_type . '.php'))
        return SINGLE_PATH . '/single-' . $post-&gt;post_type . '.php';
}

/* Checks for single template by category. Check by category slug and ID */
foreach((array)get_the_category() as $cat) :

    if(file_exists(SINGLE_PATH . '/single-cat-' . $cat-&gt;slug . '.php'))
        return SINGLE_PATH . '/single-cat-' . $cat-&gt;slug . '.php';

    elseif(file_exists(SINGLE_PATH . '/single-cat-' . $cat-&gt;term_id . '.php'))
        return SINGLE_PATH . '/single-cat-' . $cat-&gt;term_id . '.php';

endforeach;

/*Checks for default single post files within the single folder */
if(file_exists(SINGLE_PATH . '/single.php'))
    return SINGLE_PATH . '/single.php';

elseif(file_exists(SINGLE_PATH . '/default.php'))
    return SINGLE_PATH . '/default.php';

return $single;
}</code></pre>
<p>and just replace &#8220;POST TYPE NAME&#8221; with your custom post type name.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christopher Wulff</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-321045</link>
		<dc:creator>Christopher Wulff</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:17:25 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-321045</guid>
		<description>Love this and have used it a few times, particularly for the category-specific templates. With a new site using custom post types though, I am encountering a problem with the default use of single-{post-type} not returning the single template for the custom post type. 

How would I modify the code above to maintain the category specific single post templates while also enabling the single post type ones?</description>
		<content:encoded><![CDATA[<p>Love this and have used it a few times, particularly for the category-specific templates. With a new site using custom post types though, I am encountering a problem with the default use of single-{post-type} not returning the single template for the custom post type. </p>
<p>How would I modify the code above to maintain the category specific single post templates while also enabling the single post type ones?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeff campagna</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-296517</link>
		<dc:creator>jeff campagna</dc:creator>
		<pubDate>Wed, 16 Feb 2011 22:24:19 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-296517</guid>
		<description>Hey! Great Article, Justin!

What if the element you want to change is not in the single.php file but in the loop.php file? The loop calls the post thumbnail to appear before the post title. But I want, for a specific category, to remove that thumbnail from the loop...

Hopefully I am making myself clear.
Thanks so much for this!</description>
		<content:encoded><![CDATA[<p>Hey! Great Article, Justin!</p>
<p>What if the element you want to change is not in the single.php file but in the loop.php file? The loop calls the post thumbnail to appear before the post title. But I want, for a specific category, to remove that thumbnail from the loop&#8230;</p>
<p>Hopefully I am making myself clear.<br />
Thanks so much for this!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kostas Kontos</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-290534</link>
		<dc:creator>Kostas Kontos</dc:creator>
		<pubDate>Sat, 05 Feb 2011 19:51:26 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-290534</guid>
		<description>Hi Justin, I recently find this useful method for post templates and I&#039;m wondering if there is a way to work this trick for me. 

So if we have one post in two or more categories and we want to display the post with comments ability in one category and without comments in the other categories. Is this possible?

Thanks</description>
		<content:encoded><![CDATA[<p>Hi Justin, I recently find this useful method for post templates and I&#8217;m wondering if there is a way to work this trick for me. </p>
<p>So if we have one post in two or more categories and we want to display the post with comments ability in one category and without comments in the other categories. Is this possible?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Larry Levenson</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-264571</link>
		<dc:creator>Larry Levenson</dc:creator>
		<pubDate>Fri, 17 Dec 2010 16:24:34 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-264571</guid>
		<description>This 2+ year-old post was a life saver! Thanks! Spent several hours trying to make a custom post template work -- to no avail. I walked through this post step by step, and now my Hybrid child theme has working post templates. Thank you!

By the way, I&#039;m running this on WP Multisite 3.0.3 and it works great!</description>
		<content:encoded><![CDATA[<p>This 2+ year-old post was a life saver! Thanks! Spent several hours trying to make a custom post template work &#8212; to no avail. I walked through this post step by step, and now my Hybrid child theme has working post templates. Thank you!</p>
<p>By the way, I&#8217;m running this on WP Multisite 3.0.3 and it works great!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

