<?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>Just another WordPress site</description>
	<lastBuildDate>Tue, 26 Oct 2010 08:40:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Why do we need cat_is_ancestor_of()?</title>
		<link>http://rider.sofarider.com/wordpress-tips-and-tricks/why-do-we-need-cat_is_ancestor_of/</link>
		<comments>http://rider.sofarider.com/wordpress-tips-and-tricks/why-do-we-need-cat_is_ancestor_of/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 13:04:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[WordPress Tips and Tricks]]></category>
		<category><![CDATA[blog portfolio theme]]></category>
		<category><![CDATA[cat_is_ancestor_of]]></category>
		<category><![CDATA[dual wordpress theme]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=124</guid>
		<description><![CDATA[I bet you&#8217;ve already seen those dual themes called Blog-Portfolio or something like that. Such WordPress themes use 2 or more different layouts to render different sections of WordPress driven website. More precisely, if we talk about Blog-Portfolio theme, one layout is probably used for blog category while the other one relates to portfolio. Of <a href="http://rider.sofarider.com/wordpress-tips-and-tricks/why-do-we-need-cat_is_ancestor_of/" class="more-link">READ MORE</a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2010/09/evolution-274x150.jpg" alt="" title="evolution" width="274" height="150" class="alignnone size-thumbnail wp-image-126" />I bet you&#8217;ve already seen those dual themes called Blog-Portfolio or something like that. Such WordPress themes use 2 or more different layouts to render different sections of WordPress driven website. More precisely, if we talk about Blog-Portfolio theme, one layout is probably used for blog category while the other one relates to portfolio. Of course, we have to include single view page (template) for both blog and portfolio sections, otherwise there&#8217;s not much point in using it.<br />
So where&#8217;s the catch? Basically, all we need to do is to split &#8220;category.php&#8221; on two separate templates, something like &#8220;category_blog.php&#8221; and &#8220;category_portfolio.php&#8221;. The original &#8220;category.php&#8221; should act like a switch and decide whether to load one of the above mentioned files. The same rule generally applies to &#8220;single.php&#8221; and its two alias files (&#8220;single_blog.php&#8221; and &#8220;single_portfolio.php&#8221;).<br />
Please note that the following code example is taken out of context which means that both blog and category IDs are already known &#8211; both have been set via theme options!</p>
<pre>
<code>
&lt;?php
// template switch between Blog and Portfolio category
$aOptions = YourThemeInitClass::initOptions( false ); // load theme options
$blog_ID = (int)$aOptions[ 'blog-id' ];
$portfolio_ID = (int)$aOptions[ 'portfolio-id' ];

// get the current category
$categ_object = get_category( get_query_var( 'cat' ), false );

// who's our ancestor, blog or portfolio?
if( (int)$categ_object->category_parent > 0 ) {
	if( cat_is_ancestor_of( $blog_ID, (int)$categ_object->cat_ID ) ) include( TEMPLATEPATH . '/category_blog.php' );
	else if( cat_is_ancestor_of( $portfolio_ID, (int)$categ_object->cat_ID ) ) include( TEMPLATEPATH . '/category_portfolio.php' );
} else {
	if( (int)$categ_object->cat_ID == $blog_ID ) include( TEMPLATEPATH . '/category_blog.php' );
	else if( (int)$categ_object->cat_ID == $portfolio_ID ) include( TEMPLATEPATH . '/category_portfolio.php' );
}
?&gt;
</code>
</pre>
<p>I guess you&#8217;ve got the point so far. cat_is_ancestor_of() is supposed to check whether current category belongs to blog or portfolio part. Current category children are also treated in that manner, no matter the level of depth.<br />
You can simply paste the above code into &#8220;category.php&#8221;. Be sure to provide proper category IDs either by hard-coding them or via theme functions/options page.</p>
<h2>What about single view switch?</h2>
<p>Believe it or not, it&#8217;s even simpler. Due to the fact WordPress is about to render &#8220;single.php&#8221; (aka Post details) we already have all required info. Each of your Posts MUST belong to a certain category, otherwise it just can&#8217;t exist in the system.</p>
<pre>
<code>
&lt;?php
// template switch between Blog and Portfolio category
$aOptions = YourThemeInitClass::initOptions( false ); // load theme options
$blog_ID = (int)$aOptions[ 'blog-id' ];
$portfolio_ID = (int)$aOptions[ 'portfolio-id' ];

// 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 ]->cat_ID ) ) include( TEMPLATEPATH . '/single_blog.php' );
else if( cat_is_ancestor_of( $portfolio_ID, (int)$categ_object[ 0 ]->cat_ID ) ) include( TEMPLATEPATH . '/single_portfolio.php' );
?&gt;
</code>
</pre>
<p>Paste the above code into &#8220;single.php&#8221; template file and be sure to provide proper category IDs (in our case $blog_ID and $portfolio_ID). It&#8217;s quite clear that in case you wanna have more different layouts &#8211; more conditional statements have to be used.</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/wordpress-tips-and-tricks/why-do-we-need-cat_is_ancestor_of/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

