Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If my category URL is:

/blogs/category/foo

and my archive URL is:

/blogs/2011/02/

what's the URL for 'foo' blogs from February 2011?

share|improve this question
1  
/blogs/category/foo/?y=2011&monthnum=02 –  t31os Feb 7 '11 at 21:23
    
@t31os: If you move that to an answer we could expand it with rewrite rules, so it has nice urls! –  Jan Fabry Feb 8 '11 at 10:10
1  
Wouldn't any rules written for such a URL conflict with the sub-category rules though? I think that's why no such rules exist, how can you differentiate between a category URL that's date based, and one that's simply a sub-caegory URL. You're welcome to factor in my suggestion to your own answer if you like. –  t31os Feb 8 '11 at 10:33
    
@t31os: Hmm, it should be possible... With a non-greedy regex, and because the date archive ends with digits. I'll think about it and maybe come back with a complete answer! –  Jan Fabry Feb 8 '11 at 12:47
1  
@t31os: I expanded my answer with rewrite rules that add date-based browsing. As I thought, the non-greedy rewrite rules make this possible. –  Jan Fabry Feb 9 '11 at 15:00

2 Answers 2

There is no date-based archive for a category. The /category/[slug]/ pages are already "archives", in that they display old posts over different pages.

The different pages can be accessed by adding page/2/, page/3/, ... to the URL. The template tags to add these links are next_posts_link() and previous_posts_link().

If you want to add a date-based layer to your category archives, you can add a rewrite rule to match a year, optional month and optional paging.

add_filter( 'category_rewrite_rules', 'wpse8769_category_rewrite_rules' );
function wpse8769_category_rewrite_rules( $category_rules )
{
    global $wp_rewrite;
    // This could be incorrect for fancy permastructs, only tested in simple situations
    $category_permastruct = str_replace( $wp_rewrite->rewritecode, $wp_rewrite->rewritereplace, $wp_rewrite->get_category_permastruct() );
    $category_permastruct = preg_replace( '|^/+|', '', $category_permastruct );

    $category_extra_rules = array(
        // Or split this up over different rewrite rules, if the regex is too complicated
        // Feeds are left as an exercise for the reader
        $category_permastruct . '/([0-9]{4})(/([0-9]{1,2}))?(/page/([0-9]+))?/?$' =>
            'index.php?category_name=$matches[1]&year=$matches[2]&monthnum=$matches[4]&paged=$matches[6]',
    );

    return $category_extra_rules + $category_rules;
}
share|improve this answer
    
My /category/[slug]/ URL only displays the most recent 10 posts, with no links to any others. Is there a way I can paginate them? –  Bobby Jack Feb 7 '11 at 18:28

Q: what's the URL for 'foo' blogs from February 2011?

The URL in the context of your site is: /blogs/category/foo/?y=2011&monthnum=02

(I blatantly copied this over from a commment t31os, so credits to him for this)

share|improve this answer
    
Unfortunately, that doesn't quite work. It limits the month to February OK, but the year filter doesn't take effect, so I end up with posts from Feb 2011, Feb 2010, etc. –  Bobby Jack Feb 11 '11 at 11:35
    
... and if I change it from "y=2011" to "year=2011", I get redirected to /blogs/2011/02/ thus losing the category –  Bobby Jack Feb 11 '11 at 11:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.