函数文档

dropdown_cats()

💡 云策文档标注

概述

dropdown_cats() 是 WordPress 中一个已弃用的函数,用于生成分类下拉列表。自 2.1.0 版本起,建议使用 wp_dropdown_categories() 替代。

关键要点

  • 函数已弃用,自 WordPress 2.1.0 起应使用 wp_dropdown_categories()
  • 接受多个参数控制下拉列表行为,如排序、显示选项、隐藏空分类等
  • 内部调用 _deprecated_function() 标记弃用,并转发参数到 wp_dropdown_categories()

代码示例

function dropdown_cats($optionall = 1, $all = 'All', $orderby = 'ID', $order = 'asc',
$show_last_update = 0, $show_count = 0, $hide_empty = 1, $optionnone = false,
$selected = 0, $exclude = 0) {
_deprecated_function( __FUNCTION__, '2.1.0', 'wp_dropdown_categories()' );

$show_option_all = '';
if ( $optionall )
$show_option_all = $all;

$show_option_none = '';
if ( $optionnone )
$show_option_none = _x( 'None', 'Categories dropdown (show_option_none parameter)' );

$vars = compact('show_option_all', 'show_option_none', 'orderby', 'order',
'show_last_update', 'show_count', 'hide_empty', 'selected', 'exclude');
$query = add_query_arg($vars, '');
return wp_dropdown_categories($query);
}

注意事项

  • 使用此函数会触发弃用警告,建议更新代码以避免兼容性问题
  • 相关函数包括 wp_dropdown_categories()、_x()、_deprecated_function() 和 add_query_arg()

📄 原文内容

Deprecated method for generating a drop-down of categories.

Description

See also

Parameters

$optionallintoptional

Default:1

$allstringrequired
$orderbystringrequired
$orderstringrequired
$show_last_updateintrequired
$show_countintrequired
$hide_emptyintoptional

Default:1

$optionnonebooloptional

Default:false

$selectedintrequired
$excludeintrequired

Return

string

Source

function dropdown_cats($optionall = 1, $all = 'All', $orderby = 'ID', $order = 'asc',
		$show_last_update = 0, $show_count = 0, $hide_empty = 1, $optionnone = false,
		$selected = 0, $exclude = 0) {
	_deprecated_function( __FUNCTION__, '2.1.0', 'wp_dropdown_categories()' );

	$show_option_all = '';
	if ( $optionall )
		$show_option_all = $all;

	$show_option_none = '';
	if ( $optionnone )
		$show_option_none = _x( 'None', 'Categories dropdown (show_option_none parameter)' );

	$vars = compact('show_option_all', 'show_option_none', 'orderby', 'order',
					'show_last_update', 'show_count', 'hide_empty', 'selected', 'exclude');
	$query = add_query_arg($vars, '');
	return wp_dropdown_categories($query);
}

Changelog

Version Description
2.1.0 Deprecated. Use wp_dropdown_categories()
0.71 Introduced.