Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
wp_category_checklist() - 输出无序列表的复选框,元素的label为类别名称 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / wp_category_checklist()

wp_category_checklist( int $post_id, int $descendants_and_self, int[]|false $selected_cats = false, int[]|false $popular_cats = false, Walker $walker = null, bool $checked_ontop = true )

输出无序列表的复选框,元素的label为类别名称


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 3 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "a5b1222dbf5579dcde889eb3f6fe3a4a" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "d72d698f01562a7325d1d265501633b1" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "1830afb86b51290365d52225c7cbf580" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

cat

category 分类more...

checklist


描述

另见


参数

$post_idint可选
要生成类别checklist的文章id。默认值0.
$selected_cats不能是数组。默认值为0。
$descendants_and_selfint可选
要输出其自身及子类的类别ID。
默认值为0。
$selected_catsint[]|false可选
要被标记为选中的类别ID数组。

默认:false

$popular_catsint[]|false可选
用于接受"popular-category"样式类的类别ID数组

默认:false

$walkerWalker可选
Walker对象用于生成输出。
Default是Walker_Category_Checklist实例。

默认:null

$checked_ontopbool可选
是否将选中的项目移出层次结构并移至列表顶部。

默认:true



源码

查看源码 官方文档


更新日志

版本描述
2.5.1开始引入

使用示例

  • 示例1

    基本示例

    输出所有类别的列表:

    wp_category_checklist();
  • 示例2

    输出特定类别及其后代的列表

    wp_category_checklist( 0, $category_id = 22 );
  • 示例3

    将特定文章的所有类别标记为选中

    wp_category_checklist( $post_id = 45 );
  • 示例4

    指定要预先选择的类别数组

    $selected_cats = array( 45, 33, 118 );
    
    wp_category_checklist( 0, 0, $selected_cats );
  • 示例5

    覆盖将标记为popular的类别

    $popular = array( 45, 33, 118 );
    
    wp_category_checklist( 0, 0, false, $popular );
  • 示例6

    指定要使用的walker对象

    $walker = new My_Walker_Category_Checklist();
    
    wp_category_checklist( 0, 0, false, false, $walker );
  • 示例7

    在其余类别之前列出选中的类别

    $selected_cats = array( 45, 33, 118 );
    $checked_ontop = true;
    
    wp_category_checklist( 0, 0, $selected_cats, false, null, $checked_ontop );

    除了$post_id和$selected_cats之外,您还可以组合使用任何参数,这两个参数不应一起使用。