The Category Archive widget displays a monthly or yearly archive of posts for one specific category.
The Category Archive widget lets you show posts for one specific category. The built-in Archive widget shows posts for all 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%/).
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'];
}
}
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
Downloads: 18,407
0 of 1 support threads in the last two months have been resolved.
Got something to say? Need help?