返回介绍

wp_dropdown_cats()

发布于 2017-09-11 11:54:19 字数 2851 浏览 1021 评论 0 收藏 0

Warning: This function has been deprecated. Use wp_dropdown_categories() instead.

wp_dropdown_cats( int $currentcat,  int $currentparent,  int $parent,  int $level,  array $categories )

Legacy function used for generating a categories drop-down control.


description


参数

$currentcat

(int) (Optional) ID of the current category. Default 0.

$currentparent

(int) (Optional) Current parent category ID. Default 0.

$parent

(int) (Optional) Parent ID to retrieve categories for. Default 0.

$level

(int) (Optional) Number of levels deep to display. Default 0.

$categories

(array) (Optional) Categories to include in the control. Default 0.


返回值

(bool|null) False if no categories were found.


源代码

File: wp-admin/includes/deprecated.php

function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {
	_deprecated_function( __FUNCTION__, '3.0.0', 'wp_dropdown_categories()' );
	if (!$categories )
		$categories = get_categories( array('hide_empty' => 0) );

	if ( $categories ) {
		foreach ( $categories as $category ) {
			if ( $currentcat != $category->term_id && $parent == $category->parent) {
				$pad = str_repeat( '– ', $level );
				$category->name = esc_html( $category->name );
				echo "\n\t<option value='$category->term_id'";
				if ( $currentparent == $category->term_id )
					echo " selected='selected'";
				echo ">$pad$category->name</option>";
				wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories );
			}
		}
	} else {
		return false;
	}
}

更新日志

Versiondescription
3.0.0Use wp_dropdown_categories()
1.2.0Introduced.

相关函数

Uses

  • wp-admin/includes/deprecated.php: wp_dropdown_cats()
  • wp-includes/formatting.php: esc_html()
  • wp-includes/category.php: get_categories()
  • wp-includes/functions.php: _deprecated_function()

Used By

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

User Contributed Notes

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

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

发布评论

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