<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SofaRider &#187; blog-portfolio theme</title>
	<atom:link href="http://rider.sofarider.com/tag/blog-portfolio-theme/feed/" rel="self" type="application/rss+xml" />
	<link>http://rider.sofarider.com</link>
	<description>WordPress Themes, Widgets, Development &#124; WEB &#38; Graphic Design</description>
	<lastBuildDate>Wed, 14 Oct 2009 08:40:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dual themes and how to use cat_is_ancestor_of()</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/dual-themes-and-how-to-use-cat_is_ancestor_of-function/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/dual-themes-and-how-to-use-cat_is_ancestor_of-function/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 12:22:34 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[blog-portfolio theme]]></category>
		<category><![CDATA[dual themes]]></category>
		<category><![CDATA[how-to]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=44</guid>
		<description><![CDATA[
What kind of WordPress themes are called dual? Have you ever seen Blog-Portfolio mixed theme? Some developers take the advantage of parent-child Page relation in order to build such theme but others achieve dual functionality by creating 2 separate, root level categories. In both cases content requires different templates for a case designer wants to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2009/06/duality-1-200x200.jpg" alt="duality-1" title="duality-1" width="200" height="200" class="alignnone size-thumbnail wp-image-60" /><br />
What kind of WordPress themes are called dual? Have you ever seen Blog-Portfolio mixed theme? Some developers take the advantage of parent-child Page relation in order to build such theme but others achieve dual functionality by creating 2 separate, root level categories. In both cases content requires different templates for a case designer wants to ensure different visual experience for the site user.</p>
<p>Not sure about other developers but I prefer the second method of having categorized Portfolio. This method dictates certain rules, for example using 4 extra templates. Why four? Normally you would have 2 standard WordPress templates: <strong>category.php</strong> and <strong>single.php</strong>. In our case we will use category.php and single.php as redirect pages either to Blog or Portfolio category page or Blog and Portfolio single page. Otherwise spoken we will now have category-blog.php, category-portfolio.php, single-blog.php and single-portfolio.php templates extra.</p>
<h2>Redirection</h2>
<p>WordPress knows exactly who belongs where. Imagine you want to read the details of a certain Post whose title is clickable. After you click on it, WordPress takes you to the template named single.php and renders the content. This is how things would work &#8216;normally&#8217;. In our story, when taken to single.php, the logic must be extended a little bit:</p>
<ul>
<li>Find out which category our Post belongs to</li>
<li>Check who&#8217;s an ancestor of this category</li>
<li>Redirect user to either single-blog.php or single-portfolio.php</li>
</ul>
<p>In order to achieve all that, consider the following code:</p>
<pre>
<code>
&lt;?php
  // this is how our 'single.php' tempate looks like
  // template switch between Blog and Portfolio - single post
  $blog_ID = 1; // ID of our blog root-level category
  $portfolio_ID = 2; // ID of our portfolio root-level category
  // our post belongs to this category...
  $categ_object = get_the_category();
  // who's our ancestor, blog or portfolio?
  if( cat_is_ancestor_of( $blog_ID, (int)$categ_object[ 0 ]-&gt;cat_ID ) ) include( TEMPLATEPATH . &quot;/single-blog.php&quot; );
  else if( cat_is_ancestor_of( $portfolio_ID, (int)$categ_object[ 0 ]-&gt;cat_ID ) ) include( TEMPLATEPATH . &quot;/single-portfolio.php&quot; );
  ?&gt;
</code>
</pre>
<p>
Category ID of a Blog or Portfolio can either be hardcoded or pulled dynamically. So how it works? <strong>get_the_category()</strong> function will return required Post parent category ID. Hence we already know IDs of our root-level categories, the only thing we need now is to check who&#8217;s the ancestor. <strong>cat_is_ancestor_of()</strong> function will do the task for us and according to result (boolean, <em>true</em> or <em>false</em>) user gets redirected to the right template.</p>
<h2>Category level redirection</h2>
<p>Almost everything mentioned before will work at category level redirection. Because of the fact that we have 2 top-level categories as well, and we want to make them render differently, redirection by means of <strong>cat_is_ancestor_of()</strong> is required. So here we go:</p>
<pre>
<code>
&lt;?php
  // this is how our 'category.php' tempate looks like
  // template switch between Blog and Portfolio - category
  $blog_ID = 1; // ID of our blog root-level category
  $portfolio_ID = 2; // ID of our portfolio root-level category
  // we are here now
  $categ_object = get_category( get_query_var( 'cat' ), false );
  // who's our ancestor, blog or portfolio? First check for root category.
  if( (int)$categ_object-&gt;category_parent &gt; 0 ) {
    if( cat_is_ancestor_of( $blog_ID, (int)$categ_object-&gt;cat_ID ) ) include( TEMPLATEPATH . &quot;/category-blog.php&quot; );
    else if( cat_is_ancestor_of( $portfolio_ID, (int)$categ_object-&gt;cat_ID ) ) include( TEMPLATEPATH . &quot;/category-portfolio.php&quot; );
  } else {
  if( (int)$categ_object-&gt;cat_ID == $blog_ID ) include( TEMPLATEPATH . &quot;/category-blog.php&quot; );
  else if( (int)$categ_object-&gt;cat_ID == $portfolio_ID ) include( TEMPLATEPATH . &quot;/category-portfolio.php&quot; );
  }
?&gt;
</code>
</pre>
<p>Any comments, questions, ideas and suggestions are welcomed!</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/dual-themes-and-how-to-use-cat_is_ancestor_of-function/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
