wp_dropdown_categories()获取所有的分类目录,并创建一个下拉菜单

目录

描述

Display or retrieve the HTML dropdown list of categories.

wp_dropdown_categories() 描述

用法

 <?php wp_dropdown_categories$args ); ?> 

Default Usage

By default, the usage shows:

  • Sorts by category id in ascending order
  • Does not show the count of posts within a category
  • Does not show 'empty' categories
  • Excludes nothing
  • Displays (echos) the categories
  • No category is 'selected' in the form
  • Does not display the categories in a hierarchical structure
  • Assigns 'cat' to the form name
  • Assigns the form to the class 'postform'
  • No select ID so will default to 'name'
  • Class of postform
  • No depth limit
  • Tab index of 0
  • Use taxonomy = category
  • Hide dropdown if no terms returned
  • Outputs the term ID upon selecting the dropdown option

wp_dropdown_categories() 用法

参数

$args

(string|array) (可选) Override default arguments. See Notes.

默认值:

wp_dropdown_categories() 参数

返回值

(string) 

HTML content only if 'echo' argument is 0.

wp_dropdown_categories() 返回值

示例

Dropdown with Submit Button

Displays a hierarchical category dropdown list in HTML form with a submit button, in a WordPress sidebar unordered list, with a count of posts in each category.

Dropdown without a Submit Button using JavaScript

Example depicts using the show_option_none parameter and was gleaned from Moshu's forum post.

Dropdown without a Submit Button using JavaScript (2)

In this example the echo parameter (echo=0) is used. A simple preg_replace inserts the JavaScript code. It even works without JavaScript (submit button is wrapped by noscript tags).

wp_dropdown_categories() 示例

注意

wp_dropdown_categories() 注意

历史

  • 添加于 版本: 2.1

wp_dropdown_categories() 历史

源文件

wp_dropdown_categories() 函数的代码位于 wp-includes/category-template.php.

wp_dropdown_categories() 源文件

相关