<?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; php</title>
	<atom:link href="http://themocracy.com/tag/php/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>PHP Calendar Functions</title>
		<link>http://themocracy.com/2010/02/php-calendar-functions/</link>
		<comments>http://themocracy.com/2010/02/php-calendar-functions/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 14:24:22 +0000</pubDate>
		<dc:creator>Barrie</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=264</guid>
		<description><![CDATA[It's really easy to get really mixed up when trying to program with date functions - lots to keep track of, calendars, timezones, daylight saving, weird months that have different numbers of days in them...]]></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%2F02%2Fphp-calendar-functions%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fphp-calendar-functions%2F" height="61" width="51" /></a></div><p><img src="http://themocracy.com/wp-content/uploads/2010/02/wordpress-calendar.gif" alt="" title="wordpress-calendar" width="128" height="128" class="alignright size-full wp-image-265" />It&#8217;s really easy to get really mixed up when trying to program with date functions &#8211; lots to keep track of, calendars, timezones, daylight saving, weird months that have different numbers of days in them&#8230;</p>
<p><strong>Here&#8217;s a quick rundown on the main PHP functions involved.</strong> </p>
<h3>1. checkdate()</h3>
<blockquote><p>
bool <strong>checkdate </strong> ( int $month  , int $day  , int $year  )
</p></blockquote>
<p>Does just what it says, for the Gregorian calendar, and it&#8217;s been around since PHP4 &#8211; a very quick way to ensure that the programming isn&#8217;t coming up with any silly results. Always useful!</p>
<h3>2.. date() and gmdate()</h3>
<p>From a given UNIX timestamp, <strong>date()</strong> tells you what time would be in your server timezone and <strong>gmdate()</strong> tells you what GMT it would be (or UTC, the same thing&#8230;). It is important to get the hang of the consequences of this and one way of figuring it out is to bear in mind the date() format character &#8220;Z&#8221; &#8211; the timezone offset in seconds, positive or negative. </p>
<p>No matter what the timezone is set to, these 2 expressions will produce the same result&#8230;</p>
<pre class="brush: php">
&lt;?php
	date_default_timezone_set(&#039;America/Montreal&#039;);

	echo date(&quot;Y/m/d H:i:s&quot;,(time()));
	echo gmdate(&quot;Y/m/d H:i:s&quot;,(time()+ date(&quot;Z&quot;)));

?&gt;
</pre>
<h3>3. strtotime()</h3>
<p>Takes a string and should return a Unix timestamp.</p>
<p>It does say string in &#8220;US English date format&#8221; &#8211; which means that for strtotime (&#8220;04/06/2010&#8243;) is April 6th, and not the 4th of June. (Probably no need to get into a discussion about the relative logic of the two systems here).</p>
<p><strong>strtotime</strong> has a pretty decent understanding of language &#8211; so you can do relative times:</p>
<pre class="brush: php">
strtotime(&#039;next Monday&#039;);
strtotime(&#039;+1 years&#039;);
strtotime(&#039;first day next month&#039;);
strtotime(&#039;2010-02 last day&#039;);
</pre>
<p>All return what you&#8217;d expect, based on the datetime the function&#8217;s run&#8230;</p>
<h3>4. mktime()</h3>
<p>Good for catching &#8220;overflows&#8221;. </p>
<pre class="brush: php">
echo date(&quot;M-d-Y&quot;, mktime(0, 0, 0, 12, 32, 2009)) // =&gt; Jan-01-2010
echo date(&quot;M-d-Y&quot;, mktime(0, 0, 0, 15, 31, 2009)) // =&gt; Mar-31-2010
</pre>
<p>Like strtotime, mktime doesn&#8217;t go in unit magnitude order &#8211; it&#8217;s hours, minutes, seconds, months, days, years&#8230;. why? because that&#8217;s the decision that was made&#8230;</p>
<p><strong>Find a birth day with mktime:-</strong></p>
<pre class="brush: php">
	$my_birthdate = mktime(0,0,0,5,12,72);
	print date(&quot;l&quot;, $my_birthdate);
	//gives:   Friday
</pre>
<h3>A Few  More Calendar Tricks</h3>
<p><strong>Current age</strong></p>
<pre class="brush: php">
&lt;?php  echo floor(abs(strtotime(&#039;Y&#039;) - strtotime(&#039;02/22/1968&#039;))/31536000);  ?&gt;
</pre>
<p><strong>Easter date</strong></p>
<pre class="brush: php">
&lt;?php echo date(&quot;M-d-Y&quot;, easter_date(2010));   ?&gt;     // Apr-04-2010
</pre>
<p><strong>Datetime constants</strong><br />
PHP 5.1 and later, via the DateTime class, offers a few shorthand formatting strings.</p>
<pre class="brush: php">
&lt;?php echo date(DATE_RSS); ?&gt;
//gives something like: Thu, 21 Feb 2010 09:35:44 -0800
</pre>
<p>The defined strings are <a href="http://us.php.net/manual/en/class.datetime.php#datetime.constants.types">here</a> &#8211; also good for cookies.</p>
<p><strong>Daylight Saving Problems</strong><br />
One way of cutting out possible problems with daylight saving time differences across timezones is to work in UTC, using expressions like these (and then revert back to a local timezone at the end if necessary).</p>
<pre class="brush: php">
date_default_timezone_set(&#039;UTC&#039;);

$date_utc = strtotime($date. &quot; UTC&quot;);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/02/php-calendar-functions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WP-Cron &#8211; automating and scheduling</title>
		<link>http://themocracy.com/2010/02/wp-cron-automating-scheduling/</link>
		<comments>http://themocracy.com/2010/02/wp-cron-automating-scheduling/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 06:51:03 +0000</pubDate>
		<dc:creator>Barrie</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=260</guid>
		<description><![CDATA[You need a cron job in your WordPress blog - something run to a schedule, hourly, daily...  Instead of fixing up a crontab and using wget or lynx, you can use WordPress's internal version of the cron job.]]></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%2F02%2Fwp-cron-automating-scheduling%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fwp-cron-automating-scheduling%2F" height="61" width="51" /></a></div><p><strong>You need a cron job in your WordPress blog</strong> &#8211; something run to a schedule, hourly, daily&#8230;  Instead of fixing up a crontab and using wget or lynx, you can use WordPress&#8217;s internal version of the cron job.</p>
<p>This isn&#8217;t a true cron job, with a crontab text file sitting on the server &#8211; it&#8217;s known as a pseudo-cron. Since a script can&#8217;t launch itself, it makes use of a visitor, human or maybe robot, launching it by requesting a page. So the job actually runs at the first launch <em>after</em> the scheduled time, not necessarily at the scheduled time to the exact second.</p>
<h3>wp_schedule_event()</h3>
<p>The most convenient way of using WP-Cron is to wrap it all up in a plugin &#8211; so that the scheduling can be done just the once by including it in the plugin activation function.</p>
<pre class="brush: php">
register_activation_hook(__FILE__, &#039;my_activation&#039;);
add_action(&#039;my_hourly_event&#039;, &#039;do_this_hourly&#039;);
register_deactivation_hook(__FILE__, &#039;my_deactivation&#039;); 

function my_activation() {
wp_schedule_event(time(), &#039;hourly&#039;, &#039;my_hourly_event&#039;);
}

function my_deactivation() {
	wp_clear_scheduled_hook(&#039;my_hourly_event&#039;);
}

function do_this_hourly() {
	// do something here every hour
}
</pre>
<p>The PHP time() used as an argument indicates &#8220;as of now&#8221; &#8211; so if the plugin is activated at 11:23, an hourly event is going to run at xx:23 from now onwards.</p>
<p>If your code is in for example <strong>functions.php</strong> and is executed every time the script is executed, you don&#8217;t want to keep scheduling the same event. Something like this prevents the problem:-</p>
<pre class="brush: php">
if (empty(wp_next_scheduled(&#039;my_event&#039;)))
		wp_schedule_event(time(), &#039;daily&#039;, &#039;my_event&#039;);
</pre>
<h3> WP-Cron Hourly, Recurrence Intervals</h3>
<p>Only <strong>hourly</strong>, <strong>daily</strong> and <strong>twicedaily</strong> are available immediately &#8211;  but there&#8217;s a trick to getting more and that&#8217;s to tap into the cron_schedules filter and add a key to the schedules array.</p>
<pre class="brush: php">
add_filter(&#039;cron_schedules&#039;, &#039;my_add_weekly&#039;);

function my_add_weekly( $schedules ) {
	$schedules[&#039;weekly&#039;] = array(
		&#039;interval&#039; =&gt; 604800, //that&#039;s how many seconds in a week, for the unix timestamp
		&#039;display&#039; =&gt; __(&#039;Once Weekly&#039;)
	);
	return $schedules;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/02/wp-cron-automating-scheduling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Version Testing for WordPress Theme Design.</title>
		<link>http://themocracy.com/2010/02/wordpress-version-testing/</link>
		<comments>http://themocracy.com/2010/02/wordpress-version-testing/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 09:52:10 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=251</guid>
		<description><![CDATA[WordPress is (mainly) backwards-compatible in terms of its core code. But the code connected with themes or plugins that you add may well not be. For example, v2.9 has post thumbnails - put these in your new theme and they won't work for older installs of WordPress - so some version testing is required.]]></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%2F02%2Fwordpress-version-testing%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fwordpress-version-testing%2F" height="61" width="51" /></a></div><p><img class="alignright size-full wp-image-252" title="blueprint" src="http://themocracy.com/wp-content/uploads/2010/02/blueprint.jpg" alt="wordpress version testing" width="173" height="115" /><strong>WordPress is (mainly) backwards-compatible in terms of its core code</strong>. But the code connected with themes or plugins that you add may well not be. For example, v2.9 has post thumbnails &#8211; put these in your new theme and they won&#8217;t work for older installs of WordPress &#8211; so some version testing is required.</p>
<p>There&#8217;s 2 ways to go about this:-</p>
<p>1. If you reckon your theme is no good without the features available to the latest version, you can prevent people from installing it in the first place &#8211; a bit brutal, but it does the job.</p>
<p>In <strong>functions.php</strong>, at the top:-</p>
<pre class="brush: php">

if(version_compare(get_bloginfo(&#039;version&#039;), &#039;2.8&#039;) &lt; 0) die(__(&#039;This theme requires at least WordPress version 2.8&#039;,&#039;thistheme&#039;));
</pre>
<p>More information about how PHP&#8217;s native function version_compare works <a href="http://php.net/manual/en/function.version-compare.php">here</a>.</p>
<p>And then do tell people explicitly when they download the theme &#8211; <em>compatible with WordPress versions &gt; 2.8</em> etc.<br />
In practice, some regularly manage not to read this, so stand by for complaint emails&#8230;.</p>
<p>2. You can catch the errors before they happen &#8211; <strong>function_exists</strong>?</p>
<p>There&#8217;s a bit more work involved here. The guiding principle is to try to catch the errors as concisely as possible, rather than have a string of actions all wrapped up in their own if function_exists statements &#8211; and hopefully also offer some alternative to make sure that the degradation is as graceful as you can make it&#8230;</p>
<p>As a  basic example, the <strong>file_get_contents</strong> function arrived in PHP 4.3  &#8211; and as of now, there are still servers around with older versions of PHP than this&#8230;</p>
<pre class="brush: php">
if function_exists(&#039;file_get_contents&#039;){
//use it
$file = @file_get_contents($some_url);
} else {
// don&#039;t use it...
// and try to supply some alternative or warning
}
</pre>
<p>In the same area of grabbing a file, especially remotely, testing for curl is necessary&#8230;</p>
<pre class="brush: php">
if (function_exists(&#039;curl_open&#039;))
</pre>
<p>You can also use:</p>
<pre class="brush: php">
if  (in_array (&#039;curl&#039;, get_loaded_extensions()))
</pre>
<p>As an aside &#8211; WordPress comes with Snoopy bundled &#8211; custom-written to do the same job, but you do have to explicitly include it &#8211; so in a theme or plugin, the &#8216;official&#8217; way to do it is something like,</p>
<pre class="brush: php">
require_once(ABSPATH.WPINC.&#039;/class-snoopy.php&#039;);
$s = new Snoopy;
</pre>
<p>Lastly, and this is a very occasional thing &#8211; but since there are compiling options with PHP, (which modules are included and in which combination) a function name may exist even though the function itself can&#8217;t be used. Image functions associated with the GD extension can be a problem here, beware of functions like <strong>imagettfbbox()</strong>, <strong>imagefttext()</strong>&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/02/wordpress-version-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A jQuery Slideshow for WordPress 2.9</title>
		<link>http://themocracy.com/2010/02/jquery-slideshow-wordpress/</link>
		<comments>http://themocracy.com/2010/02/jquery-slideshow-wordpress/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 11:03:46 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[thumbnails]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=248</guid>
		<description><![CDATA[You want a jQuery slideshow for your WordPress blog? - on the front page, or maybe in the sidebar? No real problem, all the javascript is taken of with the help of a jQuery plugin, all we have to do is figure out how to get the post data. 

And to keep things really simple, this is going to use the thumbnail functions in WP 2.9 - no need to mess around with custom fields any more. ]]></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%2F02%2Fjquery-slideshow-wordpress%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fjquery-slideshow-wordpress%2F" height="61" width="51" /></a></div><p><img class="alignright size-medium wp-image-249" title="jquery-slideshow" src="http://themocracy.com/wp-content/uploads/2010/02/jquery-slideshow-300x206.gif" alt="jquery slideshow" width="245" height="168" /><strong>You want a jQuery slideshow for your WordPress blog? </strong>- on the front page, or maybe in the sidebar? No real problem, all the javascript is taken of with the help of a jQuery plugin, all we have to do is figure out how to get the post data.</p>
<p>And to keep things really simple, this is going to use the thumbnail functions in WP 2.9 &#8211; no need to mess around with custom fields any more.<br />
<span id="more-248"></span><br />
Firstly, you do have to explicitly declare the new thumbnail system in <strong>functions.php</strong> &#8211; and best to wrap it up in an &#8220;if function exists&#8221; to avoid problems for older WP installs.</p>
<pre class="brush: php">
if (function_exists(&#039;add_theme_support&#039;)) {
add_theme_support( &#039;post-thumbnails&#039; );
add_image_size(&#039;slideshow-image&#039;, 300, 160); // for front page slideshow
}
</pre>
<p>The smart move is to define a &#8220;Featured&#8221; category &#8211; any post in that category will be available for the slideshow, and that&#8217;s the selection taken care of. Create a category &#8211; call it featured, or anything, but make a note of the cat_ID &#8211; mouseover a category on the admin categories page and it&#8217;ll be in the url, something like:</p>
<blockquote><p>http://testblog.com/wp-admin/categories.php?action=edit&#038;<strong>cat_ID=3</strong></p></blockquote>
<p>The ordering will be by date, newest first. (Don&#8217;t forget you can tweak the timestamp of a post if you really want to just to get the order exactly as you want it).</p>
<p>So create a couple of posts in this category and add some thumbnails to them &#8211; since our slideshow is going to be 300px by 160px, make sure they&#8217;re bigger than that. Then, in <strong>home.php</strong>, or <strong>index.php</strong>, where ever you want the slideshow to appear, add:</p>
<pre class="brush: php">
&lt;?php

$featured_category_id = 3;
$number_of_posts = 4;

$args = array(&#039;showposts&#039;=&gt;$number_of_posts, &#039;cat&#039;=&gt;$featured_category_id);

$slideshow_query = new WP_Query($args);

?&gt;
&lt;div id=&quot;slideshow&quot;&gt;
&lt;?php
// let&#039;s keep a record of the post IDs as we go, in case we want to omit these from other post loops/lists on the same page
$duplicates = array();

while ($slideshow_query-&gt;have_posts()) : $slideshow_query-&gt;the_post();

//add the ID to the duplicates array for future reference
$duplicates[] = $id;

//test to see whether there&#039;s a thumbnail associated with the post
if (has_post_thumbnail()) {
?&gt;
&lt;div class=&quot;post-thumbnail&quot;&gt;
&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;
&lt;?php	the_post_thumbnail(&#039;slideshow-image&#039;); ?&gt;
&lt;/a&gt;
&lt;/div&gt;
&lt;?php	}
endwhile;
?&gt;
&lt;/div&gt;  &lt;!-- end of #slideshow --&gt;
</pre>
<p>Next, some javascript. We can use the excellent <a href="http://malsup.com/jquery/cycle/">jQuery Cycle Plugin</a> &#8211; as the package stands currently, we&#8217;ll use <strong>jquery.cycle.all.min.js</strong> &#8211; which allows all the possible transition effects etc. &#8211; in practice, you may well want to use the lighter versions&#8230;</p>
<p>* For a standard production site, always use <strong>min</strong> = minified,  rather than <strong>pack</strong> = packed &#8211; pack may be a smaller filesize, but it doesn&#8217;t run quicker&#8230;.</p>
<p>We need a very quick script to configure and activate the plugin &#8211; so create a new file, <strong>slideshow-activate.js</strong></p>
<pre class="brush: js">
jQuery(document).ready(function($){
$(&#039;#slideshow&#039;).cycle({
fx: &#039;fade&#039; // choose your transition type, ex: fade, scrollUp, shuffle, etc...
});
});
</pre>
<p>Later, there are lots of options here, transition speed, pausing etc. &#8211; consult the <a href="http://malsup.com/jquery/cycle/browser.html">plugin pages</a> for ideas.</p>
<p>We need to get our scripts on the WordPress page, and indicate that they depend on jQuery being loaded &#8211; making use of the WordPress functions <strong>wp_register_script</strong> and <strong>wp_enqueue_script</strong> &#8211; so in <strong>functions.php</strong></p>
<pre class="brush: php">

add_action(&#039;wp&#039;, &#039;js_head_load&#039;);

function js_head_load(){

if(is_admin()) return;  //so that we&#039;re not loading unecessary scripts in the admin

wp_register_script(&#039;cycle&#039;, get_bloginfo(&#039;template_directory&#039;)  . &#039;/scripts/jquery.cycle.all.min.js&#039;, array(&#039;jquery&#039;), &#039;1.0&#039;);

wp_enqueue_script(&#039;slideshow-activate&#039;,  get_bloginfo(&#039;template_directory&#039;)  . &#039;/scripts/slideshow-activate.js&#039;, array(&#039;jquery&#039;, &#039;cycle&#039;), &#039;1.0&#039;);

}
</pre>
<p>And then, don&#8217;t forget to put the 2 files into /scripts in your theme folder&#8230;</p>
<p>That should give you a working slideshow &#8211; ready to be styled with some CSS. Note that the way the Cycle plugin works is that it looks to rotate the immediate children of the div being called &#8211; here, they&#8217;re images, they could be eg. divs &#8211; so if you add a wrapper div(s) you may need to adjust slideshow-activate.js.</p>
<p>And if it&#8217;s not working, check first that the right scripts (jQuery, Cycle, slideshow-activate) are actually being loaded and in the right order, by looking at the page source &#8211; and check you&#8217;ve got thumbnails attached to the relevant posts&#8230;</p>
<p>You could go on to tidy this up &#8211; avoiding the hard-coded category id by having something in the theme options admin to change the id for example. Also, as said earlier, there&#8217;s a lot of scope in playing with the plugin parameters to get exactly the slideshow you want&#8230;</p>
<p>Lastly &#8211; the record of the duplicates we kept &#8211; the method for omitting them from subsequent Loops of posts is here: <a href="http://themocracy.com/2010/01/multiple-wordpress-queries-duplicates/">Multiple WordPress query duplicates</a></p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/02/jquery-slideshow-wordpress/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WordPress Action Hooks &#8211; the simplified version</title>
		<link>http://themocracy.com/2010/02/wordpress-action-hooks-the-simplified-version/</link>
		<comments>http://themocracy.com/2010/02/wordpress-action-hooks-the-simplified-version/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 09:09:01 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=237</guid>
		<description><![CDATA[WordPress action hooks allow you to access the functions of the core WP code, without messing around with that code. It's the basis for most plugins (the whole business essentially started out as the plugin API), but themes are using them more and more and there's no reason not to...

do_action/add_action are also the means of getting external scripts, CSS, javascript/jQuery correctly on the page.]]></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%2F02%2Fwordpress-action-hooks-the-simplified-version%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fwordpress-action-hooks-the-simplified-version%2F" height="61" width="51" /></a></div><p><strong>There&#8217;s no point in hacking around with the WordPress core code.</strong> You still see people doing it sometimes and happily showing off their results, but it just isn&#8217;t a good idea. Nobody else can use it without making the same hack(s), which aren&#8217;t carried through an automatic update anyway. </p>
<p>WordPress action hooks allow you to access the functions of the core WP code, without messing around with that code. It&#8217;s the basis for most plugins (the whole business essentially started out as the plugin API), but themes are using them more and more and there&#8217;s no reason not to&#8230; <strong>do_action/add_action are also the means of getting external scripts, CSS, javascript/jQuery correctly on the page.</strong><br />
<span id="more-237"></span><br />
WordPress pre-dates PHP5 and the improvements available in terms of Object-Orientated Programming (OOP). So, while there are obviously classes and objects in there, everything has a flow &#8211; once the PHP engine has compiled the code, it&#8217;s run from top to bottom &#8211; it&#8217;s procedural, as they say. </p>
<p>Instead of adding a method to a class, or extending a class with another class, there are points in the action where the possibility of doing something is left open &#8211; <strong>action hooks</strong> &#8211; either predefined, because they&#8217;ve been put in the core code, or you can create your own.</p>
<p>The means of doing it involve a couple of functions&#8230;   </p>
<h3>do_action() and add_action()</h3>
<p>Simply, <strong>do_action()</strong> is the function to create an action hook.</p>
<p>Whereas <strong>add_action()</strong> is tacking actions onto a given hook and always refers to a function that will called at that point.</p>
<pre class="brush: php">

&lt;?php do_action( $tag, $arg ); ?&gt;

&lt;?php add_action( $tag, $function_to_add, $priority, $accepted_args ); ?&gt;
</pre>
<p>The $tag is the action hook itself, a description of &#8220;where&#8221; &#8211; at what point in the action&#8230;</p>
<p>As an example, we can create an action hook that outputs some content on the home page just before the Loop of posts is output. </p>
<p>so in <strong>home.php</strong></p>
<pre class="brush: php">
 &lt;?php

 do_action( &#039;before_the_index_loop&#039; ); 

    if (have_posts()) : while (have_posts()) : the_post();
     //etc etc
?&gt;
</pre>
<p>and in <strong>functions.php</strong></p>
<pre class="brush: php">

add_action( &#039;before_the_index_loop&#039;, &#039;my_helloworld_display&#039; );

function my_helloworld_display(){

 echo &quot;&lt;p&gt;This is my hello to the world&lt;/p&gt;&quot;;

}
</pre>
<p>At the point where it reaches the action hook ( &#8216;before_the_index_loop&#8217; ) put there by the do_action, it finds a function (my_helloworld_display) to call and calls it. </p>
<p>(Or you could put this in index.php and test whether it&#8217;s running as the home page by using is_home().) </p>
<h3>Priority</h3>
<p>Everything has an order &#8211; lower to higher &#8211; and if you don&#8217;t specify it, the default value of an action is 10.</p>
<p>So here, as an example, we can add an action earlier in the document flow that&#8217;s actually going to be run <em>after</em> the next add_action.</p>
<pre class="brush: php">

add_action( &#039;my_helloworld&#039;, &#039;my_second_helloworld_display&#039;, 20);
add_action( &#039;my_helloworld&#039;, &#039;my_helloworld_display&#039;);

function my_second_helloworld_display(){
 echo &quot;&lt;p&gt;Hello again to the world&lt;/p&gt;&quot;;
}

function my_helloworld_display(){
 echo &quot;&lt;p&gt;Hello to the world&lt;/p&gt;&quot;;
}
</pre>
<p>Will produce:</p>
<blockquote><p>
Hello to the world<br />
Hello again to the world
</p></blockquote>
<h3>Accepted arguments</h3>
<p>In, say, <strong>header.php</strong>, we can place a hook with some arguments:</p>
<pre class="brush: php">

do_action( &#039;my_details&#039;, get_bloginfo(&#039;name&#039;), get_bloginfo(&#039;description&#039;));
</pre>
<p>While in <strong>functions.php</strong> we&#8217;re going to expect 2 arguments to be passed to the function.</p>
<pre class="brush: php">

add_action( &#039;my_details&#039;, &#039;my_details_display&#039;, 10 ,2);

function my_details_display($name, $description){

 echo &quot;&lt;p&gt;This is the name of my blog: {$name} and this is its description: {$description}&lt;/p&gt;&quot;;
}
</pre>
<p>(Of course, this is just for the very simple example of it, to show how arguments are passed to any function referenced by an add_action &#8211;  the whole process could have been short-cut just by putting bloginfo(&#8216;name&#8217;) on the page&#8230;)</p>
<p>In practice, it can be slightly tricky to find out the what and how many of arguments are being passed to predefined action hooks &#8211; that&#8217;s when you do have to look into the core code.</p>
<p>And just for experiment (on a development site, don&#8217;t leave lying around on anything live)</p>
<pre class="brush: php">

add_action(&#039;wp&#039;, &#039;my_vardump&#039;);

function my_vardump($query){
	global $post;
	print_r($query);
	print_r($post);
}
</pre>
<p>Just to see what&#8217;s available to play with&#8230; </p>
<p>There are a lot of action hooks strewn around the place in WordPress code already &#8211; not all of them are terribly well-documented, (it&#8217;s a large job). The thing to do is to consult first the <a href="http://codex.wordpress.org/Plugin_API/Action_Reference">Codex</a> for the main list of hooks and then experiment, adding your own hooks and making use of those already there. At least, action hooks do simplify the whole process &#8211; it&#8217;s only one line of code to comment out if things start going wrong. </p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/02/wordpress-action-hooks-the-simplified-version/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<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 Theme Frameworks</title>
		<link>http://themocracy.com/2010/01/wordpress-theme-frameworks/</link>
		<comments>http://themocracy.com/2010/01/wordpress-theme-frameworks/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 16:18:31 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Themes]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=214</guid>
		<description><![CDATA[Since the arrival of WordPress 2.7, the true framework is based on the concept of parent/child WordPress themes. A child theme is dependent on its parent - here, the framework - for its template files and functions, it's not going work without it.]]></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-theme-frameworks%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F01%2Fwordpress-theme-frameworks%2F" height="61" width="51" /></a></div><p><img class="alignright size-full wp-image-220" title="wordpress-framework" src="http://themocracy.com/wp-content/uploads/2010/01/wordpress-framework.jpg" alt="" width="290" height="169" /><strong>Since the arrival of WordPress 2.7, the true framework is based on the concept of parent/child WordPress themes.</strong></p>
<p>A child theme is dependent on its parent &#8211; here, the framework &#8211; for its template files and functions, it&#8217;s not going work without it &#8211; &#8216;parasite&#8217; might be a better name.</p>
<p>When you install a WordPress framework theme, it doesn&#8217;t look very impressive to start with &#8211; black and white &#8211; but that&#8217;s not the point. The basic idea is to cover all the fundamentals in the parent framework, the stuff every good theme needs, and keep separate the fancy styling, add-ons etc. in the child theme.<br />
<span id="more-214"></span><br />
The art of a good framework is how it lets in the customization. Much like PHP frameworks, used wisely, they allow flexibility and concise code, quickly applied &#8211; used unwisely, they rapidly become a big old mess with far too many moving parts&#8230;</p>
<p>Any good WordPress theme developer will have ended up with a core code that does the job the way he or she thinks best &#8211; and this is the origin of a framework. Frankly, if you are are more programming-orientated as a theme designer than design-orientated, they may not be for you. Whether you stick with your code, or dip into your first framework child theme, up to you&#8230; but here are the current market leaders, as it were, in no particularly significant order.</p>
<p><a href="http://themeshaper.com/thematic/">Thematic</a><br />
<a href="http://themeshaper.com/thematic/"><img class="alignright size-full wp-image-215" title="mw372" src="http://themocracy.com/wp-content/uploads/2010/01/mw372.png" alt="" width="400" height="125" /></a> Produced by Ian Stewart, the prime mover in getting parent-child themes off the ground, Thematic has grids, CSS  frameworks, and 13 different widget-ready areas. There&#8217;s a growing selection of child themes, free and premium, and support forums.</p>
<p><a href="http://themehybrid.com/">ThemeHybrid</a><br />
<a href="http://themehybrid.com/"><img class="alignright size-full wp-image-216" title="ThemeHybrid" src="http://themocracy.com/wp-content/uploads/2010/01/mw373.png" alt="" width="400" height="125" /></a>Again, all the usual goodies, ThemeHybrid also comes with a good selection of child themes built up. For enhanced support in developing and customizing your own theme, ThemeHybrid has a paid club membership option (currently US$25).</p>
<p><a href="http://www.zy.sg/the-buffet-framework/">Buffet</a><br />
<a href="http://www.zy.sg/the-buffet-framework/"><img class="alignright size-full wp-image-217" title="buffet" src="http://themocracy.com/wp-content/uploads/2010/01/mw374.png" alt="" width="400" height="125" /></a>Buffet has a variety of jQuery features &#8211; Superfish menus, SuperSleight for png transparency in IE6, jBreadcrumb.  It also offers 2 CSS frameworks &#8211; 960gs and the Blueprint CSS frameworks &#8211; and support for microformats, XOXO, hAtom, hCard&#8230;</p>
<p><a href="http://www.plaintxt.org/themes/sandbox/">Sandbox</a><br />
<a href="http://www.plaintxt.org/themes/sandbox/"><img class="alignright size-full wp-image-218" title="sandbox" src="http://themocracy.com/wp-content/uploads/2010/01/mw376.png" alt="" width="400" height="125" /></a>Sandbox is probably the original &#8211; been around for years &#8211; a minimalist Wordpress Theme, designed for developers to build on and produce workable themes simply using CSS. But it&#8217;s fully widget-ready, XHTML valid and released under the GPL.</p>
<p><a href="http://onepresscommunity.com/">OnePress</a><br />
<a href="http://onepresscommunity.com"><img class="alignright size-full wp-image-219" title="onepress" src="http://themocracy.com/wp-content/uploads/2010/01/mw371.png" alt="" width="400" height="125" /></a>The unique proposition for OnePress is its integration with phpBB, with a unified login and forum messages displayed on the blog &#8211; if you&#8217;re a jobbing site-builder this is certainly something that comes up as a very common client requirement.</p>
<p><strong>Conclusion</strong></p>
<p>There are other frameworks &#8211; many other frameworks &#8211; in different states of development. This is a hot topic in WordPress theme design and I&#8217;m sure the situation will continue to evolve &#8211; much like the arrival of javascript libraries, there&#8217;ll be a fair amount of competition before the winner(s) emerge.</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/01/wordpress-theme-frameworks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Multiple WordPress Queries &#8211; Duplicates</title>
		<link>http://themocracy.com/2010/01/multiple-wordpress-queries-duplicates/</link>
		<comments>http://themocracy.com/2010/01/multiple-wordpress-queries-duplicates/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 19:26:04 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Themes]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=197</guid>
		<description><![CDATA[You&#8217;ve got 2,3,4&#8230; custom post queries on a page and you need to get some control over duplicates &#8211; it looks unprofessional if your theme keeps showing the same stuff. Let&#8217;s take the example of displaying separately posts from 2 different categories &#8211; but if a post is in both categories, not duplicated across the [...]]]></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%2Fmultiple-wordpress-queries-duplicates%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F01%2Fmultiple-wordpress-queries-duplicates%2F" height="61" width="51" /></a></div><p><strong>You&#8217;ve got 2,3,4&#8230; custom post queries on a page and you need to get some control over duplicates</strong> &#8211; it looks unprofessional if your theme keeps showing the same stuff. Let&#8217;s take the example of displaying separately posts from 2 different categories &#8211; but if a post is in both categories, not duplicated across the lists.</p>
<p>The process is fairly simple:- 2 custom queries, but we catch a list of the post_ids as we loop through the first query, ready for their exclusion from the second.<br />
<span id="more-197"></span></p>
<pre class="brush: php">
	// declare the duplicates array - good practice
	$duplicates = array(); 

	$args = array(&#039;cat&#039; =&gt; &#039;5&#039;, &#039;showposts&#039;=&gt; &#039;10&#039;);
	$customQuery = new WP_Query($args);

	if($customQuery-&gt;have_posts()){
		while ($customQuery-&gt;have_posts()){

			$customQuery-&gt;the_post();

			//here&#039;s where we catch the ids
			$duplicates[] = $post-&gt;ID; 

			//do something with the postdata, display it etc.
		}
	}
</pre>
<p>The <strong>post__not_in</strong> parameter of a WP_Query takes an array &#8211; which is kinda useful, since an array is just what we&#8217;ve got &#8211; never say WordPress developers aren&#8217;t on the ball&#8230;.  Don&#8217;t forget, it still needs to be an array, even if you&#8217;re only passing one value. So if we continue&#8230;. </p>
<pre class="brush: php">
	$args = array(&#039;cat&#039; =&gt; &#039;6&#039;, &#039;showposts&#039;=&gt; &#039;10&#039;, &#039;post__not_in&#039; =&gt; $duplicates);
	$customQuery2 = new WP_Query($args);
		if($customQuery2-&gt;have_posts()){
	// etc etc
</pre>
<p>Another obvious application is in displaying a query of featured (category) posts and then not duplicating these posts in the later display of latest posts &#8211; a common trope in the average theme index page nowadays&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/01/multiple-wordpress-queries-duplicates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress, Twitter and URL-shortening</title>
		<link>http://themocracy.com/2010/01/wordpress-twitter-and-url-shortening/</link>
		<comments>http://themocracy.com/2010/01/wordpress-twitter-and-url-shortening/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 09:26:10 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=196</guid>
		<description><![CDATA[You&#8217;re producing a WordPress theme, or plugin, that is related to Twitter and for obvious reasons you want to include url-shortening functionality&#8230; How&#8217;s it, generally, done?
Just the briefest snippet of PHP, this example for is.gd:-

	function shorten_url($url)	{
		$request = &#039;http://is.gd/api.php?longurl=&#039; . $url;
		return @file_get_contents($request);
	}


You might want to do a bit of error-catching on that. We&#8217;ve used file_get_contents() on [...]]]></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-twitter-and-url-shortening%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F01%2Fwordpress-twitter-and-url-shortening%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" /><strong>You&#8217;re producing a WordPress theme, or plugin, that is related to Twitter </strong>and for obvious reasons you want to include url-shortening functionality&#8230; How&#8217;s it, generally, done?</p>
<p>Just the briefest snippet of PHP, this example for is.gd:-</p>
<pre class="brush: php">
	function shorten_url($url)	{
		$request = &#039;http://is.gd/api.php?longurl=&#039; . $url;
		return @file_get_contents($request);
	}
</pre>
<p><span id="more-196"></span><br />
You might want to do a bit of error-catching on that. We&#8217;ve used <strong>file_get_contents()</strong> on the basis that we write themes and plugins that work on PHP5 &#8211; the &#8216;official&#8217; WordPress way is probably still to use the bundled version of Snoopy. Or there&#8217;s always cURL &#8211; unless there isn&#8217;t on your server&#8230;</p>
<p>Any decent url-shortening service will have its own RESTful API location to do this &#8211; hunt in their Developer Tools</p>
<p>http://tinyurl.com/api-create.php?url={long_url}</p>
<p>et al&#8230; though some require login/password parameters to be passed, and some definitely require urlencoded parameters</p>
<p><strong>But&#8230;. your own name</strong></p>
<p>Don&#8217;t forget, in the particular case, if you&#8217;re customising your own WordPress installation, the possibility of using $_GET urls -these may well be short enough (if your domain name is short enough&#8230; obviously&#8230;.) . Using your own domain name has 2 advantages, 1 significant</p>
<p>1. If third parties quote the link directly on their web pages it&#8217;s your site getting the link value.<br />
2. Still works if the url-shortening site happens to die before your blog does&#8230;</p>
<p>And even if you have permalinks active, urls will redirect&#8230;.</p>
<p><a target="_blank" href="http://themocracy.com/?p=188">http://themocracy.com/?p=188</a> will redirect you to the pretty permalink version &#8211; job done.</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/01/wordpress-twitter-and-url-shortening/feed/</wfw:commentRss>
		<slash:comments>7</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>
	</channel>
</rss>
