Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

User:DavePar/Plugin API/list cats

Description

Used to change the appearance of the category list when list_cats() or wp_list_cats() is called from a theme. This filter is called in two different modes:

  1. Once for each entry in the category list.
  2. At the end of the category list.

Prototype

 list_cats_filter($content, $category) 

Examples

Will add the category ID after each category name and add "end of list" at the bottom of the category list:

add_filter('list_cats', array('foo_bar', 'list_cats_filter'), 10, 2);

class foo_bar {
    function list_cats_filter($content, $category = null) {
        if ($category == null) {
            return $content . "<li>(end of list)</li>";
        }
        else {
            return $content . " (ID={$category->cat_ID})";
        }
    }
}

Parameters

content
In mode 1, the category name. In mode 2, the entire category list.
category
In mode 1, the cooresponding category object. This parameter can be used to determine the calling mode. When 2 parameters are requested in the add_filter() call, be sure to provide a default value for this parameter. Otherwise the call will fail at run time.

Related

See list_cats(), wp_list_cats().