WordPress.org

Plugin Directory

!This plugin hasn't been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

WordPress Category Archive

The Category Archive widget displays a monthly or yearly archive of posts for one specific category.

How is the Cateogry Archive widget different than the built-in Archive widget?

The Category Archive widget lets you show posts for one specific category. The built-in Archive widget shows posts for all categories.

How come with permalinks on, when clicking on a month link, posts are shown for other months or other categories?

If permalinks are on, the permalink structure must contain the category, year and month for the Category Archive widget to work properly (e.g. /%category%/%year%/%monthnum%/%post_id%/).

How do I update the WordPress 3.0 code, so the Category Archive widget works with permalinks?

WordPress 3.0 made some code changes that effect permalinks behavior. For the Category Archive widget to work properly with permalinks set, the redirect_canonical function that handles categories, tags and taxonomies in wp-includes/canonical.php needs to be modified slightly.

The original 3.0 code:

if ( is_category() ) {
        $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);
    } elseif ( is_tag() ) {
        $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);
    } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:
        $tax = get_taxonomy( $obj->taxonomy );
        if ( false !== $tax->query_var)
            $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
        else
            $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);
    }
    $tax_url = parse_url($tax_url);
    if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
        parse_str($tax_url['query'], $query_vars);
        $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
    } else { // Taxonomy is accessable via a "pretty-URL"
        $redirect['path'] = $tax_url['path'];
    }

Update the bottom section of code that deals with tax_url to be inside the elseif ( is_tax() ) block.

if ( is_category() ) {
        $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);
    } elseif ( is_tag() ) {
        $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);
    } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:
        $tax = get_taxonomy( $obj->taxonomy );
        if ( false !== $tax->query_var)
            $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
        else
            $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);
        $tax_url = parse_url($tax_url);
        if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
            parse_str($tax_url['query'], $query_vars);
            $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
        } else { // Taxonomy is accessable via a "pretty-URL"
            $redirect['path'] = $tax_url['path'];
        }
    }

How do I update the WordPress 3.1 code, so the Category Archive widget works with permalinks?

WordPress 3.1 made some code changes that effect permalinks behavior. For the Category Archive widget to work properly with permalinks set, the redirect_canonical function that handles categories, tags and taxonomies in wp-includes/canonical.php needs to be modified slightly.

The original 3.1 code (line 167) :

$tax_url = parse_url($tax_url);
if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
    parse_str($tax_url['query'], $query_vars);
    $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
} else { // Taxonomy is accessable via a "pretty-URL"
    $redirect['path'] = $tax_url['path'];
}

Update the code so tax_url code is inside an if (is_tax()) block.

if (is_tax()) {
    $tax_url = parse_url($tax_url);
    if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
        parse_str($tax_url['query'], $query_vars);
        $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
    } else { // Taxonomy is accessable via a "pretty-URL"
        $redirect['path'] = $tax_url['path'];
    }
}

Please note, WordPress 3.1.1 works without any code changes.

Requires: 2.8.0 or higher
Compatible up to: 2.9.2
Last Updated: 2011-4-8
Active Installs: 8,000+

Ratings

5 out of 5 stars

Support

0 of 2 support threads in the last two months have been resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

1 person says it works.
0 people say it's broken.

0,1,0
50,2,1 0,1,0
40,5,2 100,3,3
40,5,2
100,3,3
0,2,0
100,1,1
33,6,2
100,3,3
100,1,1
100,1,1
100,1,1
80,5,4
100,1,1
75,4,3
100,1,1
100,2,2
100,1,1
67,3,2
100,3,3
100,1,1
100,1,1
100,1,1
100,2,2
100,1,1
100,1,1
100,1,1