<?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>Mr Mist&#039;s Blog &#187; filters</title>
	<atom:link href="http://www.misthaven.org.uk/blog/tag/filters/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.misthaven.org.uk/blog</link>
	<description>Tech News, Random Stuff, WordPress, and things going mouldy.</description>
	<lastBuildDate>Mon, 19 Jul 2010 20:42:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Filtering archives</title>
		<link>http://www.misthaven.org.uk/blog/2009/01/11/filtering-archives/</link>
		<comments>http://www.misthaven.org.uk/blog/2009/01/11/filtering-archives/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 21:37:10 +0000</pubDate>
		<dc:creator>Mrmist</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[archive]]></category>
		<category><![CDATA[filters]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.misthaven.org.uk/blog/?p=1466</guid>
		<description><![CDATA[<hr />This article is tagged with: <a href="http://www.misthaven.org.uk/blog/tag/archive/" rel="tag">archive</a>, <a href="http://www.misthaven.org.uk/blog/tag/filters/" rel="tag">filters</a>, <a href="http://www.misthaven.org.uk/blog/tag/links/" rel="tag">links</a>, <a href="http://www.misthaven.org.uk/blog/tag/wordpress/" rel="tag">WordPress</a><hr />So today I took a look at the massive list of archive links that has been steadily growing down the right-hand side of my blog since 2001. I like to have a list of links rather than the drop-down menu style, but even I had to admit that 8 years of monthly archives was getting<a style="text-decoration : none;" href="http://www.misthaven.org.uk/blog/2009/01/11/filtering-archives/"> [...]</a>]]></description>
			<content:encoded><![CDATA[<hr />This article is tagged with: <a href="http://www.misthaven.org.uk/blog/tag/archive/" rel="tag">archive</a>, <a href="http://www.misthaven.org.uk/blog/tag/filters/" rel="tag">filters</a>, <a href="http://www.misthaven.org.uk/blog/tag/links/" rel="tag">links</a>, <a href="http://www.misthaven.org.uk/blog/tag/wordpress/" rel="tag">WordPress</a><hr /><p>So today I took a look at the massive list of archive links that has been steadily growing down the right-hand side of my blog since 2001.  I like to have a list of links rather than the drop-down menu style, but even I had to admit that 8 years of monthly archives was getting a bit much.</p>
<p>So I&#8217;ve done a quick re-design.  The current year&#8217;s worth of archives are now linked monthly, with the rest being links to the yearly pages, from which each year is linked monthly.  </p>
<p>Well, I say &#8220;quick&#8221;, but it has taken a few hours I think.  Firstly I had to figure out how to get a new widget on the side-bar, as I had forgotten. Then I had to figure out how to get the wp_get_archives function to do yearly and monthly output &#8211; again, not too difficult, as that was in the Codex.  </p>
<p>But then I wanted the yearly list to miss out the current year.  Hmm.  How to do that?  There&#8217;s no parameter for that.  After a bit of digging around through the WordPress code, I learnt that you have to use a filter.  The code for my filters eventually ended up looking like this -</p>
<p><code>function mist_thisyear_getarchives_where ($sql) {<br />
global $mist_time;<br />
$post = $posts[0];<br />
if (is_year()) {<br />
        if (!isset($mist_time)) {<br />
          $mist_time = get_the_time('Y');<br />
        }<br />
$sql=$sql . ' AND YEAR(post_date) = ' . $mist_time;<br />
} else {<br />
$sql=$sql . ' AND YEAR(post_date) = YEAR (CURRENT_DATE) ';<br />
}<br />
return $sql;<br />
}</p>
<p>function mist_oldyears_getarchives_where ($sql) {<br />
global $mist_time;<br />
if (is_year()) {<br />
        if (!isset($mist_time)) {<br />
          $mist_time = get_the_time('Y');<br />
        }<br />
$sql=$sql . ' AND YEAR(post_date) != ' . $mist_time;<br />
} else {<br />
$sql=$sql . ' AND YEAR(post_date) < YEAR (CURRENT_DATE) ';<br />
}<br />
return $sql;<br />
}<br />
</code></p>
<p>And I then call the wp_get_archives function like this -</p>
<p></code><code><br />
add_filter ('getarchives_where','mist_oldyears_getarchives_where');<br />
wp_get_archives('type=yearly');<br />
remove_filter ('getarchives_where','mist_oldyears_getarchives_where');<br />
</code></p>
<p>The various filters and bits of conditional code let me have different archive lists on the Archive and other pages.  The strange bits around get_the_time are a hack, because otherwise the variable doesn&#8217;t seem to be quite right.  Instead I have to set $mist_time in my Archive template, so that it gets the correct year from the WordPress loop. </p>
<p>I hope this may be of help to anyone trying to set up slightly different archive links. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.misthaven.org.uk/blog/2009/01/11/filtering-archives/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
