<?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>Jaymin Patel &#187; wordpress-category-date-archive</title>
	<atom:link href="http://www.jayminkapish.com/tag/wordpress-category-date-archive/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jayminkapish.com</link>
	<description>Wordpress Developer, New York</description>
	<lastBuildDate>Wed, 09 Nov 2011 15:33:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>Date archive for a category</title>
		<link>http://www.jayminkapish.com/2009/06/16/date-archive-for-a-category/</link>
		<comments>http://www.jayminkapish.com/2009/06/16/date-archive-for-a-category/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 16:52:53 +0000</pubDate>
		<dc:creator>Jaymin Patel</dc:creator>
				<category><![CDATA[KAPISH]]></category>
		<category><![CDATA[Date archive for a category]]></category>
		<category><![CDATA[wordpress archives for category]]></category>
		<category><![CDATA[wordpress-category-date-archive]]></category>

		<guid isPermaLink="false">http://blog.kapish.co.in/?p=78</guid>
		<description><![CDATA[How to build date archive for a category in wordpress.]]></description>
			<content:encoded><![CDATA[<p>There are a few ideas out there <strong>How to build date archive for a category</strong>. I am joining the race now.</p>
<p>Some of us, wordpress developers, may think this is hacky but I bet a few will like it this way because <strong>this works!</strong>.<br />
<span id="more-78"></span><br />
This idea would end up in url like this</p>
<div class="phpcode"><code>/archives/category/{category-slug}/yyyy/mm/</code></div>
<p>Lets get started and you can <a href="/wp-content/uploads/2009/06/date_archive_for_category.zip" title="Download php code - Date Archive for a category - wordpress">Download code here</a> and you can put that in your active theme&#8217;s functions.php file.</p>
<p>I am going to use <strong>init</strong> hook.</p>
<div class="phpcode">
<code>add_action('init','my_date_archive_for_category');</code>
</div>
<p>We can check if incoming request contains <strong>/archives/category/</strong> inside my_date_archive_for_category function. If it does, this is our category/date archive page.</p>
<p>Now breakup incoming request, and check every part of the request. We need category slug, year and month in place.</p>
<div class="phpcode">
<code>$request_parts = explode('/', $request);</code>
</div>
<p>Parts of request</p>
<div class="phpcode">
<code>Array ( [0] => [1] => archives [2] => category [3] => category-slug [4] => yyyy [5] => mm [6] => )</code>
</div>
<p>Here, we need to validate a few parts of the request like category slug, yyyy and mm.</p>
<div class="phpcode">
<code>$category_array = get_term_by('slug', $request_parts["3"], "category", ARRAY_A);</code>
</div>
<p>Now time to query wordpress.</p>
<div class="phpcode">
<code>query_posts(array('cat'=>$category_array["term_id"], 'year'=>$request_parts["4"], 'monthnum'=>$request_parts["5"]));</code>
</div>
<p>If we have posts, display them otherwise set a flag which we can use later to show 404 so visitors do not get confused.</p>
<div class="phpcode">
<code><br />
if ( have_posts() ) : while ( have_posts() ) : the_post();<br />
........<br />
endwhile;<br />
else:<br />
$is404 = true; /* set the flag so we know no posts found and display 404. */<br />
endif;<br />
</code>
</div>
<p><strong>DO NOT FORGET</strong> to put</p>
<div class="phpcode">
<code>exit;</code>
</div>
<p>at the end.</p>
<p>Putting <strong>exit</strong> at the end will end further PHP execution on your blog.</p>
<p>Do not forget to let me know how this works on your blog.</p>
<h3>Most Commented Posts</h3><ul class="related_post"><li><a href="http://www.jayminkapish.com/2008/06/13/comments-pagination-wordpress/" title="Comments Pagination &#8211; Wordpress &#8211; Bug Fixed!">Comments Pagination &#8211; Wordpress &#8211; Bug Fixed! (22)</a></li><li><a href="http://www.jayminkapish.com/2008/01/18/wordpress-database-schema/" title="Wordpress Database Schema">Wordpress Database Schema (13)</a></li><li><a href="http://www.jayminkapish.com/2009/06/16/date-archive-for-a-category/" title="Date archive for a category">Date archive for a category (10)</a></li><li><a href="http://www.jayminkapish.com/2008/02/07/migrate-from-utw-tags-to-wordpress-23-terms/" title="Migrate Tags from UTW Tags to Wordpress 2.3 Terms">Migrate Tags from UTW Tags to Wordpress 2.3 Terms (9)</a></li><li><a href="http://www.jayminkapish.com/2009/03/17/json-and-wordpress/" title="JSON and Wordpress">JSON and Wordpress (9)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.jayminkapish.com/2009/06/16/date-archive-for-a-category/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: www.jayminkapish.com @ 2012-02-07 02:51:37 by W3 Total Cache -->
