<?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>Wed, 23 May 2012 07:51:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Brad</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-1420554</link>
		<dc:creator>Brad</dc:creator>
		<pubDate>Mon, 30 Apr 2012 11:41:48 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-1420554</guid>
		<description>I think I got it, just change &#039;taxonomy_name&#039; to whatever your custom taxonomy is called.

&lt;pre&gt;&lt;code&gt;/**
	* Checks for single template by category
	* Check by category slug and ID
	*/
	foreach((array)get_the_terms($post-&gt;ID,&#039;taxonomy_name&#039;) 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;;&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I think I got it, just change &#8216;taxonomy_name&#8217; to whatever your custom taxonomy is called.</p>
<pre><code>/**
	* Checks for single template by category
	* Check by category slug and ID
	*/
	foreach((array)get_the_terms($post-&gt;ID,'taxonomy_name') 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';</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-1420488</link>
		<dc:creator>Brad</dc:creator>
		<pubDate>Mon, 30 Apr 2012 11:34:29 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-1420488</guid>
		<description>I&#039;m with Jez, is it possible to modify it to pull a template based on a Custom Taxonomy?</description>
		<content:encoded><![CDATA[<p>I&#8217;m with Jez, is it possible to modify it to pull a template based on a Custom Taxonomy?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jez</title>
		<link>http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress#comment-622067</link>
		<dc:creator>Jez</dc:creator>
		<pubDate>Mon, 20 Feb 2012 14:49:39 +0000</pubDate>
		<guid isPermaLink="false">http://justintadlock.com/?p=1202#comment-622067</guid>
		<description>Can this be set up for single files assigned to a Custom Taxonomy?

As currently its just for default categories...

Thanks :)</description>
		<content:encoded><![CDATA[<p>Can this be set up for single files assigned to a Custom Taxonomy?</p>
<p>As currently its just for default categories&#8230;</p>
<p>Thanks <img src='http://justintadlock.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<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>
</channel>
</rss>

