Widgets Mass-Collapse

Feb 14, 2009   //   by Hackadelic   //   WordPress  //  8 Comments

From the Black HoleRecently, saintneko asked me whether it is better to implement a certain functionality as a plugin, or to theme it. The functionality in question is making sidebar widgets collapsible.

A seemingly simple question, but, as is often the case with “simple” questions, one with no simple answer at all.

The reason why no simple answer can be given is: There are just too many aspects involved. There is the themes at one side, the widgets at the other, and WordPress in between as middleman.

To my understanding of WordPress, a plugin alone won’t do, because there’s no common standard on how  widgets in WordPress look like (in terms of their HTML/CSS), or behave (in terms of WordPress actions they trigger, and filters they apply). I’d say, WordPress is most influential of the three, but I wouldn’t give hacking WordPress the slightest consideration. The theme has some influence, too, but then, it seems the inappropriate place to add functionality that is by itself theme-unrelated.

I won’t go into much detail here (yet), beyond saying that I gave it a shot and came up with a – somewhat “quick & dirty”1 – solution. I implemented it on my site (as you can easily see), and it turned all of my widgets (that is, all with a title) into collapsible citizens at once. It takes a slight modification of a single theme file, while everything else is implemented as a plugin.

I’ll post about it in more detail soon. Till then: Stay tuned!

  1. at least, it is the first shot that’s “quick & dirty” []

8 Comments

  • All these plugins need is an admin page.

    It doesn’t need to be a “collapsible widget plugin”, just a collapsible element plugin.

    A collapsible elements only needs a handle element, and a content element to hide.
    This can be applied to anything with similar markup, for example, widgets AND posts.

    This is done very easily with CSS selectors.
    The answer of doing it with a plugin, is simply giving three selector options in the admin.
    – The collapsible class
    – The handle sub class/id
    – The content sub class/id

    Options can go further if one of us decides to combine all our methods into one to become something like the shadowbox plugin.
    Maybe it can use any supported javascript library.

    I use jQuery in mine, but you might not.

    As I’ve said in my post, I’m not doing anything further now, got other fish to fry, but anyone who does I would like to see it.

    Toodles

  • I just stumbled upon another plugin today: Collapsible Widget

    You might be interested.

    • Daniel, thanks. As I’ve assumed, they all “cook with water” – very similar principles of operation (though implemented with varying code).

  • I few days ago, I installed a plugin which adds this functionnality to the sidebar widgets:

    Sidebar Widget Collapser

    To make it work, I had to make some mods on my theme, to make sur the plugin recognizes the widgets.

    I’m looking forward for your solution.

    • Daniel, thanks for the hint.

      From what I’ve read on their page, I can tell at its core their solution principle is not radically different from mine. (This is only natural, because, as it stands, that’s the only way it can be done with WordPress at all.) However, I guess it’ll be the solution details that make up the spice, and I sure will be curious to receive your feedback.

  • Wow, I was actually hoping for the title-only thing so I could have some control over what I forced upon the user 🙂 I mainly want to have things like recent comments / posts / twitter hidden until people explore.

    Wow you rock!

    • Thanks, saintneko! I’ll be preparing a public release of the solution, so you can just use it. 🙂

      Alas, it won’t be easy to achieve selective auto-collapsing of widgets, though I have an idea that might work. I’ll give it a try and see how it works out. 🙂

Blog Categories

I have come here to chew bubblegum and kick ass...
and I'm all out of bubblegum.
-- Nada in They Live