Codex

Template Tags/dropdown cats


This function has been deprecated. That means it has been replaced by a new function or is no longer supported, and may be removed from future versions. All code that uses this function should be converted to use its replacement if one exists.


Contents

Description

Displays a list of categories in a select (i.e dropdown) box.

Replace With

wp_dropdown_categories().

Usage

 <?php dropdown_cats(optionall'all''sort_column','sort_order'optiondatesoptioncount,
             
hide_emptyoptionnoneselectedhide); ?> 

Examples

Dropdown with Submit Button

Displays category select (dropdown) list in HTML form with a submit button, in a WordPress sidebar unordered list.

<li id="categories"><?php _e('Categories:'); ?>
   <ul><li>
   <form action="<?php echo $PHP_SELF ?>" method="get">
   <?php dropdown_cats(); ?>
   <input type="submit" name="submit" value="view" />
   </form>
   </li></ul>
</li>

Dropdown without Submit Button

Displays category select (dropdown) in HTML form without a submit button.

  • Download and install the plugin Drop Down Categories found here.
  • Add the following code to your header.php template file:
<script type="text/JavaScript">
<!-- function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
  • Then add the following code to wherever you'd like the dropdown categories to be displayed (for example, your sidebar.php file):
<form action="">
<select name="menu" onchange="MM_jumpMenu('parent',this,0)">
<option>Choose one</option>  
<?php dropdown_cats_exclude('name', 'asc'); ?> 
</select>
</form>

Parameters

optionall 
(boolean) Sets whether to have an option to display all categories. Valid values:
  • TRUE (Default)
  • FALSE
all 
(string) Text to display for the option to display all categories. Defaults to 'All'.
sort_column 
(string) Key to sort options by. Valid values:
  • 'ID' (Default)
  • 'name'
sort_order 
(string) Sort order for options. Valid values:
  • 'asc' (Default)
  • 'desc'
optiondates 
(boolean) Sets whether to display the date of the last post in each category. Valid values:
  • TRUE
  • FALSE (Default)
optioncount 
(boolean) Sets whether to display a count of posts in each category. Valid values:
  • TRUE
  • FALSE (Default)
hide_empty 
(boolean) Sets whether to hide (not display) categories with no posts. Valid values:
  • TRUE (Default)
  • FALSE
optionnone 
(boolean) Sets whether to have an option to display none of the categories. Valid values:
  • TRUE
  • FALSE (Default)
selected 
(integer) Sets the default selected category ID number. Defaults to current category.
hide 
(integer) Do not display this category (specified by category ID number). There is no default.

Fixes

When you choose a category when you are not on the main page, you will not move to that category. To fix this find the following line in the template where you are using Dropdown cats. <form action="<?php echo $PHP_SELF ?>" method="get"> Replace it with : <form action="<?bloginfo('url');?>/index.php" method="get">

This is a temporary fix to the problem, a real fix will probably come soon. This problem is usually only found on blogs using Apache Rewrite rules.

(Added by Chenu J, minor edit by Derek Scruggs)

Related

the_category, the_category_rss, single_cat_title, category_description, wp_dropdown_categories, wp_list_categories, in_category, get_category_parents, get_category_link, get_the_category

How to pass parameters to tags with PHP function-style parameters

Go to Template Tag index