Output an unordered list of checkbox <input> elements labeled with category names. This is essentially a convenience function for simplifying calls to wp_terms_checklist()

wp_category_checklist() 描述



wp_category_checklist() 用法


While strictly speaking all parameters are optional because there are defaults, this function is not so useful without specifying either a $post_id or an array of $selected_cats. But don't try to do both.


(integer) (可选) Mark categories associated with this post as checked. $selected_cats must be false, and not an array, if a nonzero value is passed here.

默认值: 0


(integer) (可选) ID of the category to output along with its descendents.

默认值: 0


(boolean|array) (可选) An array of category IDs to mark as checked. If passing a valid $post_id, this should be set as false.

默认值: false


(boolean|array) (可选) An array of category IDs that overrides the list of categories receiving the "popular-category" class.

默认值: false


(object) (可选) Walker object to use to build the output. If empty, an instance of Walker_Category_Checklist will be used.

默认值: null


(boolean) (可选) Move checked items out of the hierarchy and to the top of the list.

默认值: true

wp_category_checklist() 参数


Output a list off all categories:

Output a the list of a certain category and its descendants:

Mark all categories for a particular post as checked:

Specify an array of categories to preselect instead:

To override which categories will be marked as popular:

Specify a walker object to use:

List the checked categories before the rest:

You may also use any of the parameters in combination, except for $post_id and $selected_cats, which should not be used together.

wp_category_checklist() 示例


wp_category_checklist() 函数的代码位于 wp-admin/includes/template.php.

wp_category_checklist() 源文件