<?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>The One with the Thoughts of Frans &#187; Wordpress</title>
	<atom:link href="http://fransdejonge.com/category/internet/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://fransdejonge.com</link>
	<description>Just a personal blog, sharing some thoughts and findings.</description>
	<lastBuildDate>Mon, 06 Feb 2012 19:37:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Teaching WordPress Some Manners: Enabling Day/Month/Year Archives</title>
		<link>http://fransdejonge.com/2010/01/teaching-wordpress-some-manners-enabling-daymonthyear-archives/</link>
		<comments>http://fransdejonge.com/2010/01/teaching-wordpress-some-manners-enabling-daymonthyear-archives/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 13:50:23 +0000</pubDate>
		<dc:creator>Frans</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://frans.lowter.us/?p=1415</guid>
		<description><![CDATA[Wordpress can't cope with day/month/year permalinks by default.]]></description>
			<content:encoded><![CDATA[<p>WordPress can&#8217;t cope with day/month/year (<code>/%day%/%monthnum%/%year%/</code>) permalinks properly by default. I had no idea because I&#8217;ve always used year/month[/day]. It&#8217;s fine for the posts, but in the archives /date/month/year fails. Luckily WP (WordPress) supports plugins in a clever manner, and it has a great API (application programming interface).</p>
<p>Initially I tried the WP API:</p>
<pre><code>add_rewrite_rule('date/(\d{1,2})/(\d{4})', 'index.php?m=$matches[2]$matches[1]', 'top');</code></pre>
<p>This kept giving me an error which I couldn&#8217;t (be bothered to) debug since it went several functions deep into the WP core, so I gave up on the API and circumvented it with the help of <a href="http://dd32.id.au/files/wordpress/test-rewrite.php">something I found</a>.</p>
<p>Anyhow, here&#8217;s the plugin. Save in a file named rewrite-day-month-year.php or just name it whatever you like.</p>
<pre><code>&lt;?php
/*
Plugin Name: Rewrite Rules for Day/Month/Year
Plugin URI: http://frans.lowter.us/2010/01/22/teaching-wordpress-some-manners-enabling-daymonthyear-archives
Description: WordPress can't cope with /%day%/%monthnum%/%year%/ for some reason. That is to day, it fails when you try to go for an archive in the form of /date/month/year/ This teaches it some manners. Probably/hopefully shouldn't interfere with other structures, but why you'd activate it if you don't need it I wouldn't know.
Version: 1.0
License: GPL
Author: Frans
Author URI: http://frans.lowter.us

Based on http://dd32.id.au/files/wordpress/test-rewrite.php
*/

function test_add_rewrite_rules( $wp_rewrite ) {
	$new_rules = array(
		"date/(\d{2})/(\d{4})" => 'index.php?m=' . $wp_rewrite->preg_index(2) . $wp_rewrite->preg_index(1),
		"date/(\d{4})" => 'index.php?year=' . $wp_rewrite->preg_index(1)
	);
	$wp_rewrite->rules = $new_rules + $wp_rewrite->rules; //NOTE: You must add it to the start of the array, Else WP's greedy rules at the end of the array will eat the request
}

register_activation_hook( __FILE__, 'flush_rules_initiate' );
register_deactivation_hook( __FILE__, 'test_flush_rules' );
// add_action('init','test_flush_rules'); // for testing

function flush_rules_initiate() {
	// Add the permalink override stuff
	add_action('generate_rewrite_rules', 'test_add_rewrite_rules');
	test_flush_rules();
}

function test_flush_rules(){
	//Flush the rewrite rules so that the new rules from this plugin get added,
	//This should only be done when the rewrite rules are changing, Ie. When this plugin is activated(Or Deactivated), For simplicity while developing using WP Rewrite, I flush the rules on every page load
	global $wp_rewrite;
	$wp_rewrite->flush_rules();
}
?></code></pre>
]]></content:encoded>
			<wfw:commentRss>http://fransdejonge.com/2010/01/teaching-wordpress-some-manners-enabling-daymonthyear-archives/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

