返回介绍

wp_category_checklist()

发布于 2017-09-11 11:39:34 字数 4675 浏览 966 评论 0 收藏 0

wp_category_checklist( int $post_id,  int $descendants_and_self,  array $selected_cats = false,  array $popular_cats = false,  object $walker = null,  bool $checked_ontop = true )

Output an unordered list of checkbox input elements labeled with category names.


description


参数

$post_id

(int) (Optional) Post to generate a categories checklist for. Default 0. $selected_cats must not be an array. Default 0.

$descendants_and_self

(int) (Optional) ID of the category to output along with its descendants. Default 0.

$selected_cats

(array) (Optional) List of categories to mark as checked.

Default value: false

$popular_cats

(array) (Optional) List of categories to receive the "popular-category" class.

Default value: false

$walker

(object) (Optional) Walker object to use to build the output. Default is a Walker_Category_Checklist instance.

Default value: null

$checked_ontop

(bool) (Optional) Whether to move checked items out of the hierarchy and to the top of the list.

Default value: true


源代码

File: wp-admin/includes/template.php

function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
	wp_terms_checklist( $post_id, array(
		'taxonomy' => 'category',
		'descendants_and_self' => $descendants_and_self,
		'selected_cats' => $selected_cats,
		'popular_cats' => $popular_cats,
		'walker' => $walker,
		'checked_ontop' => $checked_ontop
	) );
}

更新日志

Versiondescription
2.5.1Introduced.

相关函数

Uses

  • wp-admin/includes/template.php: wp_terms_checklist()

Used By

  • wp-admin/includes/deprecated.php: dropdown_categories()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Basic Example

    Outputs a list of all categories:

    
    wp_category_checklist();
    
  2. Output a the list of a certain category and its descendants

    
    wp_category_checklist( 0, $category_id = 22 );
    

    Mark all categories for a particular post as checked

    
    wp_category_checklist( $post_id = 45 );
    

    Specify an array of categories to preselect instead

    
    $selected_cats = array( 45, 33, 118 );
    
    wp_category_checklist( 0, 0, $selected_cats );
    

    To override which categories will be marked as popular

    
    $popular = array( 45, 33, 118 );
    
    wp_category_checklist( 0, 0, false, $popular );
    

    Specify a walker object to use

    
    $walker = new My_Walker_Category_Checklist();
    
    wp_category_checklist( 0, 0, false, false, $walker );
    

    List the checked categories before the rest

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文