[wp-hackers] Date archive per category

Jeremy Clarke jer-wphackers at simianuprising.com
Mon Nov 24 17:02:02 GMT 2008

On Sun, Nov 23, 2008 at 8:20 PM, Alex Hempton-Smith
<hempsworth at googlemail.com> wrote:
> Hi all,
>   - At the moment you can visit: www.mydomain.com/2008/11/ and you will
>   receive the "Archive for November, 2008".
>   - You can also visit www.mydomain.com/category/news/ and you will receive
>   the "Archive for the 'News' category".
>   - I would like URL's like: www.mydomain.com/category/news/2008/11/ and
>   receive the "Archive for the 'News' category from November, 2008".
> I think this method of being able to sort posts by category AND date would
> be a great addition for the core. Is this already possible somehow?

We have been doing this kind of archive for a long time now but pasing
in the raw url with the variables, like


This worked up until 2.5 when the canonical urls kicked in and started
forwarding those urls to just the category page. I think Mark Jaquith
patched core though so maybe those urls work now, but I think the more
you go into these special urls the more canonical urls will break
them, so you might want to consider turning off canonical urls for
some types, I did this for anything with a _GET value for "m" so that
i can have monthly archives for authors/cats etc. Here's the code in
case you need something similar:

// --------------------------------------------
// Filter redirect_canonical to disable it for ?m=
// --------------------------------------------
// End redirection any time there is a $m value in the url
// Passing FALSE to redirect_canonical filter ends redirection
// Needed for ?cat=x&m=y style urls to work. Otherwise you are
// forwarded to category without month.

// DISABLED: this turns off canonical redirection completely, which is
overkill. see above.
// remove_filter('template_redirect', 'redirect_canonical');

function gv_redirect_canonical($redirect_url) {
	global $wp_query, $wp;
	if ((int) $_GET['m']) return FALSE;
	return $redirect_url;
} //gv_redirect_canonical()

add_filter('redirect_canonical', 'gv_redirect_canonical');

Jeremy Clarke
Code and Design | globalvoicesonline.org

More information about the wp-hackers mailing list