wp_dropdown_categories

CATEGORY TAG

What It Does

Displays a list of categories in a dropdown box.

Code

<?php wp_dropdown_categories(‘arguments’); ?>

The available arguments are as follows:

orderby

Allows you to sort the categories in different ways:

  • ‘ID’- this is the default sort order
  • ‘name’

order

Allows you to order the categories in diferent ways:

  • ‘ASC’- ascending (default value)
  • ‘DESC’- descending

show_last_update

Allows you to display the date the last post was published in each category.

  • 0 – False (default value)
  • 1 – True

show_count

Allows you to display the number of total published posts in each category.

  • 0 – False (default value)
  • 1 – True

hide_empty

Allows you to exclude categories with no posts from displaying.

  • 1 – True (default value)
  • 0 – False

child_of

Allows you to only display child categories of the parent category you specify, identified by its numerical category ID.

hierarchical

Allows you to display the categories in a hierarchial view. This makes it easier on the eyes as child categories are indented below their parent categories.

  • 0 – False (default value)
  • 1 – True (default value)

name

Allows you to assign a custom name to the dropdown form. By default, the name is “cat”.

class

Allows you to specify a custom class style to the dropdown form. By default, the class name is “postform”.

depth

Allows you to specify how many hierarchy levels are displayed. For example, you can choose to display parent categories only, or choose how many depths of child categories are also shown. By default, the value is “0″, showing all parent and child categories.

  • 0 – All Categories (default value)
  • -1 – All Categories displayed inline (no hierarchial indentions- see “hierarchical” above)
  • 1 – Shows only parent (top level) categories
  • 2,3,4,etc. – The depth of child categories you choose to be displayed

exclude

Allows you to exclude categories identified by their numerical category IDs. Multiple category numbers are seperated by commas. By default, no categories are excluded.

echo

Allows you to display bookmarks or return them for use by PHP. This is a true (default value) or false setting.

  • 1 – True (default value)
  • 0 – False

selected

Allows you to select a category by default, defined by its numerical category ID. By default, no specific category is selected.

show_option_all

Allows you to sellect multiple (or all) of the categories in the dropdown box.

show_option_none

Does not allow any of the categories in the dropdown box to actually be selected (displayed only).

An example of wp_dropdown_categories using default settings:

<?php wp_dropdown_categories(); ?>

Again, using default settings but listing all of the options for customization:

$defaults = array(‘orderby’ => ‘ID’,
‘order’ => ‘ASC’, ‘show_last_update’ => 0, ‘show_count’ => 0, ‘hide_empty’ => 1, ‘child_of’ => 0, ‘hierarchical’ => 0, ‘name’ => ‘cat’, ‘class’ => ‘postform’, ‘depth’ => 0, ‘exclude’ => ”, ‘echo’ => 1, ‘selected’ => 0, ‘show_option_all’ => ”, ‘show_option_none’ => ”);

Any of these options can be changed as shown above.