<?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: Different single post template per category wordpress</title>
	<atom:link href="http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/</link>
	<description>PHP,Wordpress,Jquery Expert</description>
	<lastBuildDate>Thu, 02 Feb 2012 10:57:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Lisa</title>
		<link>http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/comment-page-1/#comment-7069</link>
		<dc:creator>Lisa</dc:creator>
		<pubDate>Mon, 09 Jan 2012 15:13:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=586#comment-7069</guid>
		<description>Thank you. Thankyouthankyouthankyou.</description>
		<content:encoded><![CDATA[<p>Thank you. Thankyouthankyouthankyou.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bart</title>
		<link>http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/comment-page-1/#comment-5700</link>
		<dc:creator>Bart</dc:creator>
		<pubDate>Sat, 05 Nov 2011 08:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=586#comment-5700</guid>
		<description>I&#039;ll try this once more. I forgot to include my code tags:

[code]&lt;?php
  /**
   * Tests if any of a post&#039;s assigned categories are descendants of target categories
   *
   * @param int&#124;array $cats The target categories. Integer ID or array of integer IDs
   * @param int&#124;object $_post The post. Omit to test the current post in the Loop or main query
   * @return bool True if at least 1 of the post&#039;s categories is a descendant of any of the target categories
   * @see get_term_by() You can get a category by name or slug, then pass ID to this function
   * @uses get_term_children() Passes $cats
   * @uses in_category() Passes $_post (can be empty)
   * @version 2.7
   * @link http://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category
   */
  if ( ! function_exists( &#039;post_is_in_descendant_category&#039; ) ) {
	  function post_is_in_descendant_category( $cats, $_post = null ) {
		  foreach ( (array) $cats as $cat ) {
			  // get_term_children() accepts integer ID only
			  $descendants = get_term_children( (int) $cat, &#039;category&#039; );
			  if ( $descendants &amp;&amp; in_category( $descendants, $_post ) )
				  return true;
		  }
		  return false;
	  }
  }
?&gt;

&lt;?php

  $post = $wp_query-&gt;post;
  if (in_category( &#039;cat1&#039; ) &#124;&#124; post_is_in_descendant_category( get_term_by(&#039;slug&#039;,&#039;cat1&#039;,&#039;category&#039;) )) {
      include(TEMPLATEPATH.&#039;/single_cat1.php&#039;);
  } elseif (in_category( &#039;cat2&#039; ) &#124;&#124; post_is_in_descendant_category( get_term_by(&#039;slug&#039;,&#039;cat2&#039;,&#039;category&#039;) )) {
      include(TEMPLATEPATH.&#039;/single_cat2.php&#039;);
  } else {
      include(TEMPLATEPATH.&#039;/single_default.php&#039;);
  }
?&gt;
[/code]</description>
		<content:encoded><![CDATA[<p>I&#8217;ll try this once more. I forgot to include my code tags:</p>
<pre class="brush: plain; title: ; notranslate">&lt;?php
  /**
   * Tests if any of a post's assigned categories are descendants of target categories
   *
   * @param int|array $cats The target categories. Integer ID or array of integer IDs
   * @param int|object $_post The post. Omit to test the current post in the Loop or main query
   * @return bool True if at least 1 of the post's categories is a descendant of any of the target categories
   * @see get_term_by() You can get a category by name or slug, then pass ID to this function
   * @uses get_term_children() Passes $cats
   * @uses in_category() Passes $_post (can be empty)
   * @version 2.7
   * @link <a href="http://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category">http://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category</a>
   */
  if ( ! function_exists( 'post_is_in_descendant_category' ) ) {
	  function post_is_in_descendant_category( $cats, $_post = null ) {
		  foreach ( (array) $cats as $cat ) {
			  // get_term_children() accepts integer ID only
			  $descendants = get_term_children( (int) $cat, 'category' );
			  if ( $descendants &amp;&amp; in_category( $descendants, $_post ) )
				  return true;
		  }
		  return false;
	  }
  }
?&gt;

&lt;?php

  $post = $wp_query-&gt;post;
  if (in_category( 'cat1' ) || post_is_in_descendant_category( get_term_by('slug','cat1','category') )) {
      include(TEMPLATEPATH.'/single_cat1.php');
  } elseif (in_category( 'cat2' ) || post_is_in_descendant_category( get_term_by('slug','cat2','category') )) {
      include(TEMPLATEPATH.'/single_cat2.php');
  } else {
      include(TEMPLATEPATH.'/single_default.php');
  }
?&gt;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bart</title>
		<link>http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/comment-page-1/#comment-5699</link>
		<dc:creator>Bart</dc:creator>
		<pubDate>Sat, 05 Nov 2011 08:24:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=586#comment-5699</guid>
		<description>Great solution. I modified it slightly to fit my needs, as I have subcategories and I wanted to include them in my template (without having to update the code each time I added a new subcategory).

Here&#039;s my code:



post;
  if (in_category( &#039;cat1&#039; ) &#124;&#124; post_is_in_descendant_category( get_term_by(&#039;slug&#039;,&#039;cat1&#039;,&#039;category&#039;) )) {
      include(TEMPLATEPATH.&#039;/single_cat1.php&#039;);
  } elseif (in_category( &#039;cat2&#039; ) &#124;&#124; post_is_in_descendant_category( get_term_by(&#039;slug&#039;,&#039;cat2&#039;,&#039;category&#039;) )) {
      include(TEMPLATEPATH.&#039;/single_cat2.php&#039;);
  } else {
      include(TEMPLATEPATH.&#039;/single_default.php&#039;);
  }
?&gt;</description>
		<content:encoded><![CDATA[<p>Great solution. I modified it slightly to fit my needs, as I have subcategories and I wanted to include them in my template (without having to update the code each time I added a new subcategory).</p>
<p>Here&#8217;s my code:</p>
<p>post;<br />
  if (in_category( &#8216;cat1&#8242; ) || post_is_in_descendant_category( get_term_by(&#8216;slug&#8217;,'cat1&#8242;,&#8217;category&#8217;) )) {<br />
      include(TEMPLATEPATH.&#8217;/single_cat1.php&#8217;);<br />
  } elseif (in_category( &#8216;cat2&#8242; ) || post_is_in_descendant_category( get_term_by(&#8216;slug&#8217;,'cat2&#8242;,&#8217;category&#8217;) )) {<br />
      include(TEMPLATEPATH.&#8217;/single_cat2.php&#8217;);<br />
  } else {<br />
      include(TEMPLATEPATH.&#8217;/single_default.php&#8217;);<br />
  }<br />
?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kortita</title>
		<link>http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/comment-page-1/#comment-5531</link>
		<dc:creator>kortita</dc:creator>
		<pubDate>Tue, 25 Oct 2011 09:52:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=586#comment-5531</guid>
		<description>Oh My God!!!!
Realy realy thank you for your share, i have been more than 72 hours without sleep for stupid this code, i founded many articles like this but all off sucks explanation and always following error, YOU ARE GOOD SIMPLE EXPLANATION for newbies like me,

Good share sir!! God Bless you!!!</description>
		<content:encoded><![CDATA[<p>Oh My God!!!!<br />
Realy realy thank you for your share, i have been more than 72 hours without sleep for stupid this code, i founded many articles like this but all off sucks explanation and always following error, YOU ARE GOOD SIMPLE EXPLANATION for newbies like me,</p>
<p>Good share sir!! God Bless you!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ericv</title>
		<link>http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/comment-page-1/#comment-5380</link>
		<dc:creator>Ericv</dc:creator>
		<pubDate>Sat, 15 Oct 2011 08:51:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=586#comment-5380</guid>
		<description>That&#039;s what I&#039;m searching for. Great!</description>
		<content:encoded><![CDATA[<p>That&#8217;s what I&#8217;m searching for. Great!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/comment-page-1/#comment-4955</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Tue, 23 Aug 2011 15:05:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=586#comment-4955</guid>
		<description>Just what I was looking for. Thanks.</description>
		<content:encoded><![CDATA[<p>Just what I was looking for. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mr.T</title>
		<link>http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/comment-page-1/#comment-4739</link>
		<dc:creator>Mr.T</dc:creator>
		<pubDate>Tue, 26 Jul 2011 19:26:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=586#comment-4739</guid>
		<description>I was messing around with filters and complicated stuff when I stumbled upon your post. Thank you.</description>
		<content:encoded><![CDATA[<p>I was messing around with filters and complicated stuff when I stumbled upon your post. Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: randyyanuar</title>
		<link>http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/comment-page-1/#comment-4732</link>
		<dc:creator>randyyanuar</dc:creator>
		<pubDate>Mon, 25 Jul 2011 10:19:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=586#comment-4732</guid>
		<description>so simple.. this is what i really need.. thanks a bunch dude... :)</description>
		<content:encoded><![CDATA[<p>so simple.. this is what i really need.. thanks a bunch dude&#8230; <img src='http://www.snilesh.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stacey</title>
		<link>http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/comment-page-1/#comment-4727</link>
		<dc:creator>stacey</dc:creator>
		<pubDate>Sat, 23 Jul 2011 18:24:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=586#comment-4727</guid>
		<description>I really like the posting ... was easy to follow and very helpful while I was reading it ... except, it&#039;s not working for me.  
This is driving me nuts because it seems so simple but I&#039;m having trouble.  
Because I&#039;m using a child template, I had to change my code to:
post;
  if (in_category(&#039;doggonecrazy&#039;)) {
     include(&#039;http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-doggonecrazy.php&#039;);
  } elseif (in_category(&#039;humanrants&#039;)) {
     include(&#039;http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-humanrants.php&#039;);
  } elseif(in_category(&#039;quote&#039;)) {
     include(&#039;http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-quote.php&#039;);
  }  
  else{
     include(&#039;http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-rainbow.php&#039;);
  }
?&gt;

This is actually getting the right template file to open because I&#039;m getting

Fatal error: Call to undefined function get_header() in /home/stacey/public_html/wp-content/themes/Nala-theme/single-cat-humanrants.php on line 10 

Why is it telling me that get_header() is undefined?  I&#039;ve been messing with it for hours and maybe it is obvious but I guess I&#039;m missing the forest for the trees but I can&#039;t seem to figure it out. 

If I replace single.php with it&#039;s orginal code, including the call to get_header() it will go back to the way it was before.  

Any help would be apprectiated,
Thanks</description>
		<content:encoded><![CDATA[<p>I really like the posting &#8230; was easy to follow and very helpful while I was reading it &#8230; except, it&#8217;s not working for me.<br />
This is driving me nuts because it seems so simple but I&#8217;m having trouble.<br />
Because I&#8217;m using a child template, I had to change my code to:<br />
post;<br />
  if (in_category(&#8216;doggonecrazy&#8217;)) {<br />
     include(&#8216;<a href="http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-doggonecrazy.php">http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-doggonecrazy.php</a>&#8216;);<br />
  } elseif (in_category(&#8216;humanrants&#8217;)) {<br />
     include(&#8216;<a href="http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-humanrants.php">http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-humanrants.php</a>&#8216;);<br />
  } elseif(in_category(&#8216;quote&#8217;)) {<br />
     include(&#8216;<a href="http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-quote.php">http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-quote.php</a>&#8216;);<br />
  }<br />
  else{<br />
     include(&#8216;<a href="http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-rainbow.php">http://crazydoglife.com/wp-content/themes/Nala-theme/single-cat-rainbow.php</a>&#8216;);<br />
  }<br />
?&gt;</p>
<p>This is actually getting the right template file to open because I&#8217;m getting</p>
<p>Fatal error: Call to undefined function get_header() in /home/stacey/public_html/wp-content/themes/Nala-theme/single-cat-humanrants.php on line 10 </p>
<p>Why is it telling me that get_header() is undefined?  I&#8217;ve been messing with it for hours and maybe it is obvious but I guess I&#8217;m missing the forest for the trees but I can&#8217;t seem to figure it out. </p>
<p>If I replace single.php with it&#8217;s orginal code, including the call to get_header() it will go back to the way it was before.  </p>
<p>Any help would be apprectiated,<br />
Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Thomas</title>
		<link>http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/different-single-post-template-per-category-wordpress/comment-page-1/#comment-4393</link>
		<dc:creator>Michael Thomas</dc:creator>
		<pubDate>Tue, 28 Jun 2011 09:11:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=586#comment-4393</guid>
		<description>That is BRILLIANT!!!! Thank you so much for your help that has made my life as a web designer much easier! That is exactly what I need in my web design!!!</description>
		<content:encoded><![CDATA[<p>That is BRILLIANT!!!! Thank you so much for your help that has made my life as a web designer much easier! That is exactly what I need in my web design!!!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

