<?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>a work on process &#187; whitehallinnovationhub</title>
	<atom:link href="http://jystewart.net/process/tag/whitehallinnovationhub/feed/" rel="self" type="application/rss+xml" />
	<link>http://jystewart.net/process</link>
	<description>notes from another web developer</description>
	<lastBuildDate>Tue, 27 Jul 2010 09:53:43 +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 and &#8220;Pathless Categories&#8221;</title>
		<link>http://jystewart.net/process/2009/04/wordpress-and-pathless-categories/</link>
		<comments>http://jystewart.net/process/2009/04/wordpress-and-pathless-categories/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 11:25:54 +0000</pubDate>
		<dc:creator>James Stewart</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[categories]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[pathless categories]]></category>
		<category><![CDATA[permalinks]]></category>
		<category><![CDATA[subcategories]]></category>
		<category><![CDATA[whitehallinnovationhub]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://jystewart.net/process/?p=616</guid>
		<description><![CDATA[I&#8217;m working on a wordpress project at the moment, and pushing that blogging engine quite a bit further than I have before. We&#8217;re going to be using categories very extensively and one of the first tasks has been to allow category paths without any preceding /category/ or the like. By default, wordpress wants the category <a href="http://jystewart.net/process/2009/04/wordpress-and-pathless-categories/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a wordpress project at the moment, and pushing that blogging engine quite a bit further than I have before. We&#8217;re going to be using categories very extensively and one of the first tasks has been to allow category paths without any preceding /category/ or the like. By default, wordpress wants the category with a slug of &#8216;case-studies&#8217; to live at:</p>
<p>/category/case-studies</p>
<p>but we want it to be simply:</p>
<p>/case-studies</p>
<p>So far, so straightforward. I installed the <a href="http://www.anothercoder.com/wordpress/pathless-category-permalinks-plugin">pathless-category-links plugin</a> and all was well. Until I started using subcategories. All subcategory links started returning 404s. It seems I&#8217;m far from alone in that problem, but I&#8217;ve not yet seen a solution offered, so a little digging was required.</p>
<p>What was happening with subcategories (at least in my setup) was that the wordpress method that parses the query string was identifying the top-level category name as the category name and the subcategory name as the &#8216;name&#8217; (ie. the post slug to look for). What was needed was a check to see whether that &#8216;name&#8217; maps to a category slug and if so, correct wordpress&#8217; assumption.</p>
<p>The code I&#8217;m using is:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jys_pathless_category_links_query_string'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">function</span> jys_pathless_category_links_query_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$qs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$qs</span><span style="color: #339933;">,</span> <span style="color: #000088;">$query_vars</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_vars</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> get_category_by_slug<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_vars</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$query_vars</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$query_vars</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$qs</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'query_string'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'jys_pathless_category_links_query_string'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>(NB: This will break if you have permalinks set up as recommended by the plugin author (&#8216;/%category%/%postname%&#8217;) and a post in your top-level category with the same slug as your subcategory. But hopefully that&#8217;s rare enough that we&#8217;ll be okay!)</p>
]]></content:encoded>
			<wfw:commentRss>http://jystewart.net/process/2009/04/wordpress-and-pathless-categories/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
