wp_dropdown_cats()WP 1.2.0

Устарела с версии 3.0.0. Больше не поддерживается и может быть удалена. Используйте wp_dropdown_categories().

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

Хуков нет.

Возвращает

null|false. Void on success, false if no categories were found.

Использование

wp_dropdown_cats( $current_cat, $current_parent, $category_parent, $level, $categories );
$current_cat(int)
ID of the current category.
$current_parent(int)
Current parent category ID.
$category_parent(int)
Parent ID to retrieve categories for.
$level(int)
Number of levels deep to display.
$categories(массив)
Categories to include in the control.

Заметки

Список изменений

С версии 1.2.0 Введена.
Устарела с 3.0.0 Use wp_dropdown_categories()

Код wp_dropdown_cats() WP 6.5.2

function wp_dropdown_cats( $current_cat = 0, $current_parent = 0, $category_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 ( $current_cat != $category->term_id && $category_parent == $category->parent) {
				$pad = str_repeat( '– ', $level );
				$category->name = esc_html( $category->name );
				echo "\n\t<option value='$category->term_id'";
				if ( $current_parent == $category->term_id )
					echo " selected='selected'";
				echo ">$pad$category->name</option>";
				wp_dropdown_cats( $current_cat, $current_parent, $category->term_id, $level +1, $categories );
			}
		}
	} else {
		return false;
	}
}