What’s the URL for a category archive?

If my category URL is:

/blogs/category/foo

Read More

and my archive URL is:

/blogs/2011/02/

what’s the URL for ‘foo’ blogs from February 2011?

Related posts

Leave a Reply

2 comments

  1. 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;
    }
    
  2. 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)