WordPress Category Archive Widget Plugin

Introduction

The WordPress Category Archive Widget displays a monthly or yearly archive of posts for one specific category. It is very similar to the WordPress Archive Widget except that it just displays one specific category’s posts, not all categories. It can be configured to either show a listing or pulldown by month or year with or without post counts.

Download

Screenshots

Category Archive Options

From the Category Archive widget control, you can set the widget’s title, category, whether to display the archive as lines or as an unordered list or as a pulldown, whether to group by month or year and whether to show post counts.

Category Archive Display

The archive displayed as a list with post counts and the archive as a pulldown of years without post counts.

Installation

  1. Upload “wp-category-archive.php” to the “/wp-content/plugins/” directory.
  2. Activate the plugin through the “Plugins” menu in WordPress.
  3. From the “Widgets” page in WordPress drag the “Cateogry Archive” widget to the “Sidebar”.
  4. Configure the “Category Archive” widget controls, setting the “Title”, “Category”, “Display Style”, “Group By” and “Show Post Counts” fields.

FAQ

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%/).

With WordPress 3.0, you may also need to update the redirect_canonical function in wp-includes/canonical.php. See the “Permalink rewriting in 3.0″ support topic for more info.

Change Log

1.3.0

  • Added better support for permalinks.
  • Internationalized the month names.

1.2.0

  • Added options to show post counts and display as an unordered list.

1.1.0

  • Added option to display by month or year.

1.0.0

  • Displays monthly archive of posts for one specific category.

67 Responses to “WordPress Category Archive Widget Plugin”

  1. Vrinda says:

    Thanks for the plug-in! It is just what I was looking for.

    I’m having one problem with it: the categories aren’t getting sorted by year. When I click on 2009, for example, I see the posts from all years. It’s probably because of my permalinks. I’m using a custom structure:

    /%category%/%year%/%monthnum%/%postname%/

    Any ideas what I might do to get it to sort correctly?

    Thanks!

  2. hugh says:

    It is working for me with the same permalink structure (with WordPress 2.9.2).
    What is the URL that gets created when you select a year from the pulldown?
    I get something like:

    http://www.prdream.com/wordpress/?m=2003&cat=2

  3. Jocelyn says:

    The plugin sorts by the correct category but it is not doing correctly by month. Any ideas?

  4. hugh says:

    The plugin calls get_posts with orderby, which was modified in version 2.6 of WordPress. Are you using 2.6 or higher?

    get_posts(“numberposts=-1&offset=0&category=” . $category_id . “&orderby=date&order=DESC”);

  5. hugh says:

    You might need the category, year and month to be in the permalink. Something like:

    /%category%/%year%/%monthnum%/%postname%/

    or

    /%category%/%year%/%monthnum%/%post_id%/

  6. Fernando says:

    Hi,

    This dosent appear to be working for me. The plugin is creating the widget, which is displaying the months with the count correctly, but when I click on the month/link it does not display a filtered list.

    You can see in this link if you click on april(1) you see all 9 of my posts.

    http://www.reuma.graph-byte.com/pubs/

    My permalink structure is: /%category%/%year%/%monthnum%/%postname%/

    What am I doing wrong?

    Gracias,

    Fernando
    Bori

  7. Jan says:

    Hi,

    How can I make the names of the months change to my default language setting which is Dutch?

  8. hugh says:

    To display the month names in the current locale’s language, try changing the line

    $current_year_month_display = date($display_format, $post_date);

    to

    $current_year_month_display = date_i18n($display_format, $post_date)

    If it works, let me know.

  9. Jan says:

    Hi Hugh,

    This works fine!
    Thanks for your help.

  10. Paul says:

    I have installed this plugin but it doesn’t work. When i have it set to list the category “daily-videos” it takes me to http://www.mysite.com/category/daily-videos/

    I have 3 months and it displays the amount of post per month per category correctly, however when i click on an older month it just takes me to that category. Please help.

    Paul

  11. Mike says:

    Has this issue been fixed yet?

    I too have the Month with the correct number of posts by the side, but when I click the month it shows all of the posts in the category, not posts created in that month.

  12. Paul says:

    I have been trying to get this to work for the past two days with permalinks and I still can’t figure it out. Hugh… If you could please help me out with this that would be awesome.

    Thanks in advance.
    Paul

  13. hugh says:

    I think category, year and month need to be in the permalink, so

    /%category%/%year%/%monthnum%/%post_id%/

    will work, but

    /%year%/%monthnum%/%post_id%/

    won’t.

  14. Paul says:

    I have it set to that now and it still doesn’t rewrite properly. Is there something else that can be causing this issue?

  15. hugh says:

    I updated the code (v1.3) to work better with permalinks. When permalinks are on, the links to the category archive listings are in the format /category_slug/year/month or /year/month/category_slug. If permalinks are off, the links are in the form ?m=yearmonth&cat=cat_id.

    With permalinks on, it requires that %category%, %year% and %month% are part of the permalink structure.

  16. Paul says:

    Hi hugh,

    Thank you so much!!! That worked like a charm!

  17. Meesh says:

    Upgraded to 1.3 from 1.2 and links are still in ?m=yearmonth&cat=cat_id format — is there anything else I have to do to get the new version to kick in? thanx

  18. hugh says:

    What is your permalink structure? It will default back to ?m=yearmonth&cat=cat_id if the permalink structure doesn’t contain %category% and %year%.

  19. Meesh says:

    It’s set to the common “Day and Name” format, which explains why! Thanks for the quick response.

  20. Mike says:

    My current permalink structure is:

    /%category%/%postname%.php

    Do I need to change this to get this working? If so what should I change it to without messing up my current structure?

  21. Mike says:

    OK I upgraded the plugin and used the following permalink structure:

    /%category%/%year%/%monthnum%/%post_id%/

    WORKS LIKE A CHARM

    Thankyou for the great plugin Hugh!!

  22. Phil says:

    I was wondering why the following permalink structure:

    /%category%/%year%/%monthnum%/%postname%/

    works like a charm in WP 2.9.2, but not in WP 3 RC1. Is WP 3 lacking certain rewrite rules?

    Thanks.

    -phil

  23. David says:

    Thanks heaps for this. I was worried a bit about what my client wanted but this fits it perfectly. I had a bit of trouble with the permalinks but the comments you left to other users fixed it straight away.

  24. Alain says:

    Hi,

    First of all great plugin!
    I have two questions.

    1. Is there a way to add this via a function in my template files instead of via a widget?

    2. Is there a more safe solution than the canonical.php modification for WP3.0? So on updates it keeps woking…

    Thanks, ALain

  25. hugh says:

    1. I haven’t worked with templates before. I would think you could turn the code from the widget into a function the template could use.

    2. From what I can tell, there isn’t a way in WP 3.0 to show an archive listing of posts for a particular category and year and month if permalinks are set.

    So you either need to:
    a. fix canonical.php in WP 3.0,
    b. don’t use permalinks in WP 3.0 or
    c. use older version of WP like 2.9.2.

    Hopefully a future version of WordPress (3.2) will contain a fix.

  26. Andrea says:

    I was excited to find this widget, but I have the same issue, even after making the fix to canonical.php

    I am using the permalink structure: /%category%/%year%/%monthnum%/%postname%/

    Even when my URL says “../blog/2010/04/” I am seeing all blog posts instead of just those for April 2010.

    Has anyone else still had an issue after making the fix?

  27. hugh says:

    Try the permalink structure

    /%year%/%monthnum%/%category%/%postname%/

  28. Andrea says:

    Thanks for the suggestion… I changed my permalink structure, but still no luck.

    I upgraded to WordPress 3.0.1 tonight (and noticed that they fixed canonical.php) but whatever my issue is, is still present.

  29. mmj says:

    this is just the kind of widget/plugin I was looking for – however, I was wondering whether there is a way to run it dynamically – let’s say I’m on a regular page, it should show all the posts by date/month – if I’m on an archive page of a specific category, it should just show the entries under that category

    thanks

  30. chris says:

    Hi
    Great plugin! It’s a perfect match for the setup of our website :-)

    Maybe just one thing: On line 59 I had to change ‘&cat=’ to ‘&cat=’ in order to make the site pass the w3 validation.

    Nevertheless, great stuff.

    cheers

  31. hugh says:

    Chris can you paste your changes (the full line 59). I can’t tell the difference between ‘&cat=’ and ‘&cat=’ in your last message.

  32. chris says:

    Ooops. I meant that you can replace the & with &.amp; (you need to remove the . after the &. I had to put it in the commment, otherwise it would display another & :-/)

  33. poisonborz says:

    Hola,
    Chris, could you please describe how to call this function in bare form (not as a widget)?

    I simply want to generate a good ol’ select with category archive months listed between tags…
    Thanks

  34. dude says:

    Is there any way to have this appear only on selected pages or posts?

  35. rebekah says:

    Exactly what I’ve been looking for!! Thanks!

  36. AJ says:

    hey chris

    just come across your plugin. will this be updated for wordpress 3.1?

    I installed it but I couldn’t drag the widget across to my sidebar. It just didn’t work :(

    really looking forward to using this plugin.

    hope this gets upgraded soon :)

  37. SImon says:

    @dude – use the widget logic plugin

    This plugin has huge potential but I am having problems with WP3.1

    My permalink structure is /%category%/%year%/%monthnum%/%post_id%/. I can see the link looks right when I mouse over. But WP redirects to the category, so it shows the entire category.

    How do I resolve this?

  38. hugh says:

    See the category archive plugin FAQ.

    To get the plugin to work with permalinks in WP3.1, you need to update the redirect_canonical() function in wp-includes/canonical.php. On line 167, wrap the following code:

    
    $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'];
    }
    

    in 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'];
        }
    }
    

    Note: No code changes are needed for WP 3.1.1 or higher (or WP 2.9.2).

  39. aljuk says:

    “the permalink structure must contain the category, year and month for the Category Archive widget to work properly”

    My structure is /%year%%monthnum%%day%/%category%/%postname%/ which satisfies the statement above, and I’ve wrapped the if conditional as above and per your faq, but it’s 404′ing.

    Do I take it that it will only work with exactly category/year/month etc. ie. ‘category’ has to come first?

  40. aljuk says:

    With further testing, /%year%%monthnum%%day%/%postname%/ is working for me fine, when combined with the hack to canonical.php

  41. Edle says:

    Hi! Is it possible to change the names of the months to a language that isn’t the default language? I see that the code:

    $current_year_month_display = date_i18n($display_format, $post_date)

    is added to the wp-category-archive.php page. But this only set the language that I have in the WordPress backend. I want to have the archive months listed in norwegian language, and I use english as language in WP backend.

  42. hugh says:

    It is a hack, but you could update the month names in the wp_locale object before calling date_i18n.

    $orig_months = $GLOBALS['wp_locale']->month;
    $GLOBALS['wp_locale']->month = array ('01' => 'januar', '02' => 'februar', '03' => 'mars', '04' => 'april', '05' => 'mai', '06' => 'juni', '07' => 'juli', '08' => 'august', '09' => 'september', '10' => 'oktober', '11' => 'november', '12' => 'desember');
    $current_year_month_display = date_i18n($display_format, $post_date);
    $GLOBALS['wp_locale']->month = $orig_months;

  43. Edle says:

    Okey, could you please show how and where I add this code in the wp-category-archive.php page as I’m not so familiar with php?
    Thanks!

  44. Edle says:

    Never mind, I got it working! Thank you so much! :)

  45. Robert says:

    Hi, will there be an update for work with WordPress 3.2.1?

  46. Alex says:

    Hi, great plugin,
    I’m having trouble to make it show more than just the last ten posts of the chosen category. Does it have any kind of limit for the amount of posts to show?

    You can find it working in http://www.argyor.com/comentarios/

    Thanks for the support.

  47. Alex says:

    Fixed, it was a theme limitation, it was meant to show only 10 posts in category pages.

    Thanks a lot!!

  48. Christian says:

    How I could change the name of months to spanish ?

Leave a Reply

You must be logged in to post a comment.