WordPress Plugin: Collapsible Archive Widget

Update: 20 January 2010: This plugin has not been tested with WordPress 2.9 and may break because 2.9 has internal changes. I am still trying to find time. Sorry for the Inconvenience.

I have written another simple WordPress plugin that simply display a collapsible archive in the sidebar. You can see it in action in the rightmost sidebar of the main page.

When the sidebar loads, it is in collapsed state and can be expanded by clicking the years. It utilizes simple JavaScript that shows and hides a div containing the monthly links. The purpose of this plugin is to save space on the sidebar especially if you have been blogging for a while. It is an alternative to the combo box (select) provided by the default archive widget.

My request for the plugin to be listed in the WordPress Plugin Directory has been pending for a while so for now it can be downloaded here.

The plugin can now be downloaded here.

Configuration:

  • Widget Title: the title of the widget
  • Show post counts for year: Whether or not to show the post number for each year
  • Show post counts for month: Whether or not to show the post number for each month
  • Abbreviate month names: Check this box to show abbreviation of month names
  • Hide year from month names: Do not print year after month names
  • Use script.aculo.us effects: Whether or not to show effects
  • Expand effect: Effect to use when expanding the list
  • Collapse effect: Effect to use when collapsing the list
  • Expand the list by default: Check this box to have the list expanded when loaded
  • Expand current year by default: Check this box to have the current year expanded when loaded
  • Expand current month by default: Check this box to have the current month expanded when loaded
  • Show individual posts: Show posts in the list. This should be used in extra caution; if you have a lot of posts consider disabling it as this will take time to load
  • Use HTML arrows instead of images (► ▼)
  • Show current month in bold: show current month in bold
  • Show a link to plugin page. Thank you for your support! : Display a link to plugin page (this page) as a support method

Current Version: 2.3.1

Installation

Copy the file to the wp-content/plugins/widgets directory and activate it in the Plugins page. Then drag and configure it in the Sidebar Widgets page.

Warning: Will only work on widgets enabled blogs.

TODO (these are being considered but there is no guarantee when they are going to be included)

  • Add ability for multiple instances
  • Add ability to work as non-widget
  • Add ability to include / exclude categories
  • Expand previous month rather the current
  • Research the practicality to use CSS / allow CSS options
  • List posts without year and month headers (for blogs with few posts)
  • Do not list the posts that are listed on the main page

Change Log

  • 03-Aug-2007: Initial version
  • 04-Sep-2007: Added ability to select whether to use abbreviations for the month names, and script.aculo.us effects!
  • 27-Sep-2007: Fixed javascript include – effects.js added and scriptaculous.js removed (For some reason it worked in 2.2)
  • 10-Nov-2007: Added ability to display posts (with caution), to expand by default, and also added plus and minus signs as expand/collapse buttons
  • 24-Aug-2008: Multiple updates:
    • Enqueue javascripts using WordPress API wp_enqueue_script
    • Validation as XHTML 1.0 Transitional
    • Add option to expand current year and/or month by default
    • REMOVED list type option
    • Added ability to upload own plus and minus images
    • Added ability to display plugin link. If you’d like to support this plugin, having the “powered by” on your blog is the best way; it’s our only promotion or advertising.
  • 25-Aug-2008: Bugfix to not load javascripts when effects is not used
  • 25-Aug-2008: Javascript code factoring and added ability to use HTML arrows
  • 16-Mar-2009: Separated year and month posts counts, added option to hide year after month names, ability to show current month in bold, enabled localized title
  • 17-Mar-2009: Fixed valid XHTML, and highlight (bold) bugfix


BIG FAT WARNING

The ability to display posts is provided after receiving so many requests for it. This feature is not practical for those with many posts in a month. Enabling it means that there is a lot more data that needs to be received by the browser, not to mention the load on the database. It is, however works very nice for blogs with low post count. Please use at your own risk and remember to test it.

Notes:

11-Nov-2007: I’d like to thank Meitar Moscovitz who tried his best to provide a patch to display posts in the list. I rewritten some of the code for version 2.1 based on his logic. Thank you!
25-Aug-2008: Thanks to Berny for his idea of re factoring the javascript code and also for providing HTML arrows option.

If you find this plugin useful, feel free to


0 Shares

132 thoughts on “WordPress Plugin: Collapsible Archive Widget”

  1. hi ady,

    thanks for the quick reply. – i think that this function is still not really well documented.

    btw. last night i included your plugin in my sandbox to verify the generated output. unfortunately, the code produced is not valid xhtml. i tried all three options (br, p, ul). the reason is that you’re immediately closing the html tag (eg. li) after the year.

    i hope that you got some time to fix that, because i like your plugin but also rely on valid code.

    cheers,
    berny

  2. @berny: Guilty as charged. I admit I never really validate the output when writing the plugin. To make this happen I shall be validating code with WordPress default theme, some of the time theme authors also takes valid code for granted.

  3. Hello. I was wondering if you had the previous version available for download. The new version automatically enqueues a lot of scripts which I don’t want loaded.

  4. A fix has been made. JavaScript will only be enqueued by this plugin if effects are enabled.

    @Rishi: I’ve emailed you the older version. I have just started using tags so now versions are available here.

  5. hi ady,

    thanks heaps for the quick re-coding. now everything works and validates like a charm.

    i modified your plugin a bit to include the html-arrow-characters instead of the images. – here’s the code snippet if you want to use it (as an option for example 🙂 )…


    $ara_collapsible_icons['plus'] = '►';
    $ara_collapsible_icons['minus'] = '▼';

    furthermore, i head another look at the produced code. – imho you could save a lot of locs if you would use a js-function instead of having the js-code within each onclick function.

    anyway, thanks once more and keep up the good work!

    greetz,
    berny

  6. I can’t resist simple updates. I have upgraded the plugin yet again, to version 2.2.1.1

    The items in the TODO list are bigger so that would take some time 😉

  7. Love the widget, but I was wondering if it was possible for plugin to generate css tags, currently the styling is hampering the visual style that I am going for. Otherwise I love the app.

  8. Ady. I apologize for my wording. I was working late. I meant if the Plug-in could provide markups so they can be styled via CSS. Like generating custom or predefined classes and id’s.

    Say for each story link,
    currently ” IES Light Fix : mel
    changed 2 “….”

    and say the headers changed 2

    I see that you have id’s already in the ul and in the spans, but they are very specific, and figure its used to make the plugin work, but if there was a generic id that could be added along with it.
    Kinda new to this stuff, but I would hate to modify my style.css to change the coloring for each individual branch.

    -Alex

  9. I agree with Ian up there. I think this is an excellent plugin and I was wondering if there was any chance of a sister-plugin for blogroll/links/categories?

    Again, great work. Thanks.

  10. I see in the documentation that you have listed the ability to change the list type: li, p, br. I don’t see anywhere in the widget where this can be set – was this function removed? Thanks!

    1. I did not plan to ignore you, I just realized. Yes, the ability has been removed because it caused so much overhead and ugly output so I am not sticking to a bullet list.

  11. great plugin you made !
    is there a way to display the previous year instead the currrent year ? (changing the plugin code ?)

    thank you
    be well
    jG

  12. Searched high and low for an archive showing individual posts, at last striking it rich, thanks. I’ve got to confess, I’m a little intimidated by the combined technical know-how embodied in the foregoing questions and answers, however here goes.
    1. For sites with limited number of posts stretching over years, is there a possibility to omit the month/year heading and show posts only instead, IOW to be given the choice to use or not to use the month/year?
    2. If WP is set to show the last (say) 10 posts (Settings/Reading), it’s hardly necessary to include them in the archives shown on Home page. Let alone the current exclusive expand setting for month/year. For my purposes it would be advantageous to expand previous (in lieu of current) posts only, with the choice of adding year or even month when needed later. Could I do something about this myself? On second thoughts rather not if at all avoidable.
    Hope this makes sense. (If not possible, it certainly will not distract from the usefulness of your plugin/widget as is)
    ernst

    1. Wow… that’s long, and yes that makes sense. However it’s too complicated to be implemented. But I will surely consider it for the next release. Thanks.

  13. I’m new to bloggong & My blog is about basics of Software Testing,Manual Testing,SDLC,Testing Techniques,Levels of Testing,Types of Testing,Test Planning,Test Execution,Test Development,Bug Tracking,Result Analysis,Test Design Techniques and QTP. so I write about that which I know.Give it a visit if you get a chance..
    feel to free to visit:http://huh.blogspot.com/
    Regards,
    Murali

    1. If you’re new to bloggong how come the blog contains posts back from the previous years? Your comment is not related to the post, and is purely for advertising your blog. It’s insulting.

    1. Yeah, but it’s too small to update as a new version. I think it’s ugly too. If you’re feeling adventurous you can edit the file collapsible-archive.php line 421 and 422:

      From:

      421
      422
      
      $ara_collapsible_icons['plus'][1] = '►';
      $ara_collapsible_icons['minus'][1] = '▼';

      To:

      421
      422
      
      $ara_collapsible_icons['plus'][1] = '► ';
      $ara_collapsible_icons['minus'][1] = '▼ ';

      This is a space:

       
    2. Thanks again! I’d only add that anyone looking to make the same edit should also add the space to the code a few lines above, which governs the display of the icon (your code is for the HTML arrows).

  14. Excellent plugin, but “Expand current month by default” option doesn’t seem to be working! (Here: http://jayewells.com/testsite/)

    Is there a quick way to fix this? I’m familiar with PHP but don’t much like messing with other people’s code!

    Thanks for the great work!

    ps: I’m not sure if it’s on your todo list, but it’d be great if the months could show the post counts, as well!

    1. I see it’s working now on the real site? I didn’t really notice whether the test site contained a post for March (current month when you posted the comment). But I just tested the latest version and saw no problem with or without the effects. I hope you enjoy the plugin.

      Post counts for month added to TODO list. I don’t remember why it was not added before.

    2. Hi Ady,

      Thanks yes, I was super-tired when working on this & had completely forgotten that it had just turned into March! Silly girl! Thanks again for the great plugin!

    3. No problem, I am glad you enjoyed using the plugin. I was also super tired when I received your comment, hence the delay. 🙂

      Love your work, great design.

  15. Hi Ady,

    I like your plugin!
    Is there a possibility to highlight the current month? For example make the month bold?
    And an other (not so important) question: Could I remove the year after the month?

    Best Regards from Germany, Florian

  16. Heya,

    I was just wondering, is there also an update coming with a month post count? I am not a super star with PHP but I think more people then just me would like to have that kind of feature.

    I am delighted I finally found this plug-in, cos all others just suck soo much, and this one rocks! Whoehoe! 😀

    Thanks in advance. 🙂

  17. New release 2.3 is avaialble.

    @Florian: added option to make the current month bold and the option to remove or hide the year after month names.

    @Matthijs: Post count settings are now separated between year and months

    There are still some todo… the ones done above are minor changes and to test in 2.7.1

Comments are closed.