Disclosable WP Categories


This is probably a sign of bad blogging… but I have too many categories already. Maybe if I stuck to one uber-specific topic, I wouldn’t have this problem–but that wouldn’t be nearly as much fun. What I needed instead was a decent way of controlling which categories are displayed. After looking around for awhile, I didn’t really find any plugins that did just what I wanted: limit the category display to only those that have a certain number of categories. Several of them allow you to designate certain categories as public or private or hide them completely from the home page, but I didn’t want to hide them for good.

I just wanted disclosable categories.
As you can see on the right, I decided to to just hack the files myself and get it working. It was actually a pretty simple fix. There are a couple of places in the category-building PHP file that make SQL calls. I simply added an extra parameter to the SELECT statement: (category_count < 6) as disclosable. Then, wherever the

  • elements are drawn, I throw in a little extra logic to add “id=’disclosable’” and set the display to none to all of the categories with less than 6 entries. Finally, I just throw in a little javascript to toggle them all on/off and a link at the bottom of the categories to act as the toggle.It could certainly be prettier–and it could stand to be made configurable from the WP plugins menu. For now, though, it does exactly what I want (though I may make the toggle
  • align to the right to set it off). Cleaning it up and making it reusable falls pretty low on my to-do list at the moment, but if there’s demand for this sort if thing it might certainly get bumped up!
    1. No comments yet.
    (will not be published)