<?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; programming</title>
	<atom:link href="http://themocracy.com/tag/programming/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 &#8211; Display Random Posts</title>
		<link>http://themocracy.com/2010/01/wordpress-random-posts/</link>
		<comments>http://themocracy.com/2010/01/wordpress-random-posts/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 15:06:05 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=198</guid>
		<description><![CDATA[So you want to display a random list of posts, maybe in a sidebar widget… One way to do it is to use the query_posts() function, but this isn't always the best...]]></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%2F2010%2F01%2Fwordpress-random-posts%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F01%2Fwordpress-random-posts%2F" height="61" width="51" /></a></div><p><strong>So you want to display a random list of posts, maybe in a sidebar widget&#8230; </strong></p>
<p>One way to do it is to use the <strong>query_posts()</strong> function</p>
<pre class="brush: php">
&lt;?php
    query_posts(&#039;showposts=6&amp;amp;amp;orderby=rand&#039;); 

    if (have_posts(){
	while (have_posts()){
	the_post();

	//do something with the postdata
	}
}
?&gt;
</pre>
<p>But it&#8217;s easy to get in a mess with <strong>query_posts</strong> &#8211; as they do say&#8230;<br />
<span id="more-198"></span></p>
<blockquote><p>The query_posts function overrides and replaces the main query for the page. To save your sanity, do not use it for any other purpose.</p></blockquote>
<p>Often best to instantiate a new, completely separate object where you can see it, as it were:</p>
<pre class="brush: php">
	$args = array(&#039;showposts&#039;=&gt;6, &#039;orderby&#039;=&gt;&#039;rand&#039;);
	$customQuery = new WP_Query($args);

	if($customQuery-&gt;have_posts()){
		while ($customQuery-&gt;have_posts()){
			$customQuery-&gt;the_post();
	//do something with the postdata
 }

}
</pre>
<p>It&#8217;s a good general rule to get into the practice of using WP_Query in cases like these &#8211; a lot safer&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/01/wordpress-random-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Custom Category Archives</title>
		<link>http://themocracy.com/2010/01/wordpress-custom-category-archives/</link>
		<comments>http://themocracy.com/2010/01/wordpress-custom-category-archives/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 15:05:00 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=206</guid>
		<description><![CDATA[Note, we&#8217;re talking here about different category archive pages &#8211; not having a post page customised according to the category that post is in&#8230;.
There&#8217;s 2 ways of doing this &#8211; first, the simple way, for more minor changes to the overall theme template, you can use the is_category function: 

if (is_category(&#039;featured&#039;)) {
// some different code [...]]]></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%2F2010%2F01%2Fwordpress-custom-category-archives%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F01%2Fwordpress-custom-category-archives%2F" height="61" width="51" /></a></div><p><img src="http://themocracy.com/wp-content/uploads/2010/01/wordpress-250x250-150x150.png" alt="" title="wordpress-250x250" width="150" height="150" class="alignright size-thumbnail wp-image-207" />Note, we&#8217;re talking here about different category archive pages &#8211; not having a post page customised according to the category that post is in&#8230;.</p>
<p>There&#8217;s 2 ways of doing this &#8211; first, the simple way, for more minor changes to the overall theme template, you can use the <strong>is_category</strong> function: <span id="more-206"></span></p>
<pre class="brush: php">
if (is_category(&#039;featured&#039;)) {
// some different code here for the featured category archive
// such as, if this code is in the header, load a different or supplementary stylesheet
} else {
//code here for every other category - if required...
}
</pre>
<p>So for example, you could have a category set aside for video posts and have its archive page display extra information about each post, using <strong>get_post_meta()</strong>&#8230;<br />
And <strong>single_cat_title()</strong> has its uses in this context.</p>
<p><strong>Custom Category Templates</strong></p>
<p>But secondly, just like WordPress page templates, you can customise by category by using a separate template file.</p>
<p>All you need to do is copy say, <strong>category.php</strong> to a new file: <strong>category-video.php</strong> and make the desired changes. This way, WordPress will find and load this file for you, via its priority in the template hierarchy</p>
<p>The template hierarchy: WordPress works down the list, checking for a match &#8211; the first file found that satisfies the criteria is the one used to display the archives for that category.</p>
<p>1st. category-<strong>slug</strong>.php &#8211;  define category using its slug name (WP 2.9+ only)<br />
2nd. category-<strong>ID</strong>.php &#8211; define category using its ID<br />
3rd. category.php<br />
4th. archive.php<br />
5th. index.php &#8211; the default template</p>
<p>(Note also, it&#8217;s a hypen not an underscore)</p>
<p>This does amount to roughly the same thing as a conditional php include, but can be a more elegant way of doing things&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/01/wordpress-custom-category-archives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Multi-user Themes</title>
		<link>http://themocracy.com/2009/11/wordpress-multi-user-themes/</link>
		<comments>http://themocracy.com/2009/11/wordpress-multi-user-themes/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 13:08:16 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Themes]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[multi-user]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=188</guid>
		<description><![CDATA[Sorry, but we don&#8217;t guarantee that our themes, free or premium, will work 100% if used in a WordPress multi-user environment. 
Why not? Simply because there&#8217;s too great a variation in paths, subdomains and subfolders etc. and it just doesn&#8217;t seem to be possible to cover all eventualities &#8211; at present, anyway. This isn&#8217;t particularly [...]]]></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%2F11%2Fwordpress-multi-user-themes%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2009%2F11%2Fwordpress-multi-user-themes%2F" height="61" width="51" /></a></div><p><img class="alignright size-full wp-image-189" title="wordpress multi-user " src="http://themocracy.com/wp-content/uploads/2009/10/mu-header.png" alt="wordpress multi-user " width="200" height="56" />Sorry, but we don&#8217;t guarantee that our themes, free or premium, will work 100% if used in a WordPress multi-user environment. </p>
<p>Why not? Simply because there&#8217;s too great a variation in paths, subdomains and subfolders etc. and it just doesn&#8217;t seem to be possible to cover all eventualities &#8211; at present, anyway. This isn&#8217;t particularly the fault of the WordPress multi-user developers &#8211; it&#8217;s more about how Apache, mod_rewrite and the whims of hosting sysadmins fit together at the moment.</p>
<p>Themes can be made to work &#8211; on an individual basis, depending on your installation. But a lot of this will involve editing of paths in the theme functions.php, both for wp-content/ with things like loaded jQuery scripts and also wp-includes/ for including basic scripts, such as jQuery itself, permalinks and even images.</p>
<p>Also, not everyone has access to their server&#8217;s http.conf &#8211; and there are a number of tricks here, mainly involving AllowOverride, that can be used to get results with multi-user. It&#8217;s no good saying do this, and our themes will definitely work, if you can&#8217;t get at the actual file&#8230;</p>
<p>You might get lucky, if there&#8217;s luck in programming, and it will work straight out of the box &#8211; but, as I say, no guarantee.</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2009/11/wordpress-multi-user-themes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>
