<?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>Themocracy WordPress Themes &#187; template</title>
	<atom:link href="http://themocracy.com/tag/template/feed/" rel="self" type="application/rss+xml" />
	<link>http://themocracy.com</link>
	<description>WordPress Theme Design</description>
	<lastBuildDate>Mon, 26 Jul 2010 06:18:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress Theme Functions</title>
		<link>http://themocracy.com/2009/08/wordpress-theme-functions/</link>
		<comments>http://themocracy.com/2009/08/wordpress-theme-functions/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 13:17:05 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=151</guid>
		<description><![CDATA[1. Conditional functions
To begin at the beginning, we&#8217;re talking about is_home(), is_search() etc. The whole collection of functions is here &#8211; and the majority are handled in a very similar way. 
This family of conditional functions is related to the template file hierarchy &#8211; and since their use can save a lot of time and [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthemocracy.com%2F2009%2F08%2Fwordpress-theme-functions%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2009%2F08%2Fwordpress-theme-functions%2F" height="61" width="51" /></a></div><p><img src="http://themocracy.com/wp-content/uploads/2009/08/wordpress-theme.jpg" alt="wordpress-theme" title="wordpress-theme" width="150" height="150" class="alignright size-full wp-image-153" /><strong>1. Conditional functions</strong></p>
<p>To begin at the beginning, we&#8217;re talking about <strong>is_home()</strong>, <strong>is_search()</strong> etc. The whole collection of functions is <a href="http://codex.wordpress.org/Conditional_Tags">here</a> &#8211; and the majority are handled in a very similar way. </p>
<p>This family of conditional functions is related to the template file hierarchy &#8211; and since their use can save a lot of time and duplication of code, it&#8217;s definitely worth learning how to manipulate them efficiently.<br />
<span id="more-151"></span><br />
<strong>Template Hierarchy</strong></p>
<p>Depending on the initial query, WordPress &#8216;decides&#8217; which type of page, an archive page, a search page, a page page, is being requested &#8211; it then searches whether there&#8217;s a specific template file in the theme directory corresponding to this request &#8211; ie search.php, archive.php, page.php.</p>
<p>If there is, well and good &#8211; if there isn&#8217;t, it tries the next file down in the hierarchy, and if none fit the bill, it serves up the default, index.php.</p>
<p>And this is where one very common use of conditional functions comes in -<br />
<em>Using is_search() in index.php comes to much the same thing as using a search.php file</em>. If you&#8217;re planning only a few variations in code this is the way to go. </p>
<p>So, here&#8217;s an example of a control structure in index.php, testing whether the requested page is a search page, with is_search() returning a boolean value (true/false) and according to the result, adding (or not) a heading&#8230;</p>
<pre class="brush: php">&lt;?php if (is_search()) { ?&gt;
	&lt;h2 id=&quot;pagetitle&quot;&gt;You searched for: &lt;?php the_search_query(); ?&gt;&lt;/h2&gt;
&lt;?php } ?&gt;
</pre>
<p>Roughly speaking, doing it this way is the better programming practice &#8211; if nothing else, there&#8217;s fewer files to go through and update if you want to make a small change in display etc. later. But best to get your head round both ways of doing it &#8211; there will be times when one or the other will be better suited to the purpose. </p>
<p>One slight gotcha, that&#8217;s fortunately receding into the mists of time, concerns is_home() and what happens if a static page is used as the index. Different, older, versions of WordPress will still produce variable results here &#8211; since WP2.5 the favoured test for the default home is <strong>is_front_page()</strong> &#8211; but you can&#8217;t guarantee what version of WordPress your theme might be used with, so some caution here&#8230;</p>
<p>And lastly, in the usual &#8211; slightly idiosyncratic &#8211; WordPress way, these are still referred to as Conditional Tags, just to create a small confusion with tags that are tags&#8230;</p>
<p>Next, a look at what can happen when a few values are plugged into these functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2009/08/wordpress-theme-functions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
