wp_category_checklist()获取所有分类,并且已checklist的形式输出

目录

描述

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() 描述

用法

<?php
   wp_category_checklist
$post_id$descendants_and_self$selected_cats,
         
$popular_cats$walker$checked_ontop);
?>

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.

$post_id

(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

$descendants_and_self

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

默认值: 0

$selected_cats

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

默认值: false

$popular_cats

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

默认值: false

$walker

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

默认值: null

$checked_ontop

(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() 源文件

相关