Flexible Category Lists for WordPress

January 12th, 2007

One of the side effect of overloading (perverting?) the WordPress category system to do tagging is you end up with over 1000 categories. The posting interface gets unhappy, and the wp_list_cats template tag becomes pretty much useless.

(This post is another WordPress meta post, one of several I’ve got queued up in my head, and probably interesting to 3 people in the known universe, but here you go.)

better_cat_lists is WordPress plugin that adds a couple of more flexible methods.

wp_list_popular_categories

works like wp_list_cats, but only categories with $cat_threshold posts in them.

wp_list_popular_categories('sort_column=name&cat_threshold=20');

wp_list_recent_categories

works like wp_list_cats, but only from posts with the last $n days. You can also limit the total number with $cat_limit

wp_list_recent_categories('days_ago=180&cat_limit=80');

Both methods use the same hack, they overload the list_cats_exclusions callback to do positive match instead of the intended negative match – appending and cat_ID in ($cat_ids) to the exclusion string. PHP at its finest, quick and dirty, like monkey patching but without language level support for it.

2 responses to “Flexible Category Lists for WordPress”

  1. Ernie Oporto says:

    Needs updating for WP 2.3

  2. kellan says:

    You’re right Ernie, I’ve got a bunch of code which is broken for 2.3 :-/