wp_dropdown_categories [ WordPress Function ]
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Display or retrieve the HTML dropdown list of categories.
The list of arguments is below: 'show_option_all' (string) - Text to display for showing all categories. 'show_option_none' (string) - Text to display for showing no categories. 'orderby' (string) default is 'ID' - What column to use for ordering the categories. 'order' (string) default is 'ASC' - What direction to order categories. 'show_count' (bool|int) default is 0 - Whether to show how many posts are in the category. 'hide_empty' (bool|int) default is 1 - Whether to hide categories that don't have any posts attached to them. 'child_of' (int) default is 0 - See {@link get_categories()}. 'exclude' (string) - See {@link get_categories()}. 'echo' (bool|int) default is 1 - Whether to display or retrieve content. 'depth' (int) - The max depth. 'tab_index' (int) - Tab index for select element. 'name' (string) - The name attribute value for select element. 'id' (string) - The ID attribute value for select element. Defaults to name if omitted. 'class' (string) - The class attribute value for select element. 'selected' (int) - Which category ID is selected. 'taxonomy' (string) - The name of the taxonomy to retrieve. Defaults to category.
The 'hierarchical' argument, which is disabled by default, will override the depth argument, unless it is true. When the argument is false, it will display all of the categories. When it is enabled it will use the value in the 'depth' argument.
Source
<?php
function wp_dropdown_categories( $args = '' ) {
$defaults = array(
'show_option_all' => '', 'show_option_none' => '',
'orderby' => 'id', 'order' => 'ASC',
'show_count' => 0,
'hide_empty' => 1, 'child_of' => 0,
'exclude' => '', 'echo' => 1,
'selected' => 0, 'hierarchical' => 0,
'name' => 'cat', 'id' => '',
'class' => 'postform', 'depth' => 0,
'tab_index' => 0, 'taxonomy' => 'category',
'hide_if_empty' => false
);
$defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
// Back compat.
if ( isset( $args['type'] ) && 'link' == $args['type'] ) {
_deprecated_argument( __FUNCTION__, '3.0', '' );
$args['taxonomy'] = 'link_category';
}
$r = wp_parse_args( $args, $defaults );
if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
$r['pad_counts'] = true;
}
extract( $r );
$tab_index_attribute = '';
if ( (int) $tab_index > 0 )
$tab_index_attribute = " tabindex=\"$tab_index\"";
$categories = get_terms( $taxonomy, $r );
$name = esc_attr( $name );
$class = esc_attr( $class );
$id = $id ? esc_attr( $id ) : $name;
if ( ! $r['hide_if_empty'] || ! empty($categories) )
$output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
else
$output = '';
if ( empty($categories) && ! $r['hide_if_empty'] && !empty($show_option_none) ) {
$show_option_none = apply_filters( 'list_cats', $show_option_none );
$output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
}
if ( ! empty( $categories ) ) {
if ( $show_option_all ) {
$show_option_all = apply_filters( 'list_cats', $show_option_all );
$selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
$output .= "\t<option value='0'$selected>$show_option_all</option>\n";
}
if ( $show_option_none ) {
$show_option_none = apply_filters( 'list_cats', $show_option_none );
$selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';
$output .= "\t<option value='-1'$selected>$show_option_none</option>\n";
}
if ( $hierarchical )
$depth = $r['depth']; // Walk the full depth.
else
$depth = -1; // Flat.
$output .= walk_category_dropdown_tree( $categories, $depth, $r );
}
if ( ! $r['hide_if_empty'] || ! empty($categories) )
$output .= "</select>\n";
$output = apply_filters( 'wp_dropdown_cats', $output );
if ( $echo )
echo $output;
return $output;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/wp dropdown categories « WordPress Codex
Function Reference/wp dropdown categories. Languages: ...
codex.wordpress.org - WordPress › Support » Tags — wp_dropdown_categories
Problem with wp_dropdown_categories function, 2, PhpcoSqsil, 1 month ... Show specific category with child in wp_dropdown_categories (CPT), 1, Puanthanh ...
wordpress.org - wp_dropdown_categories with taxonomies :: Anmari
Sep 26, 2010 ... Until this bug 13258 is fixed, if you are trying to get the wordpress function wp_dropdown_categories() to work with custom taxonomies, then ...
webdesign.anmari.com - Creating Custom wp_dropdown_categories - WordPress
Mar 8, 2011 ... Now I am trying to include only the profile meta field value (I said above) in the wp dropdown categories as default and hide it in my custom ...
wordpress.stackexchange.com
Gebruikersdiscussies [ wordpress.org ]
- PhpcoSqsil on "Problem with wp_dropdown_categories function"
- PhpcoSqsil on "Problem with wp_dropdown_categories function"
- elmediano on "wp_dropdown_categories not working any ideas?"
- jeezyo on "Multiple Select with wp_dropdown_categories"
- SantaSativa on "wp_dropdown_categories not working any ideas?"
- josefdunne on "custom_taxonomy drop down works, but is not heirachical"
- Puanthanh on "Show specific category with child in wp_dropdown_categories (CPT)"
- lalindsey on "wp_dropdown_categories question"
- esox on "DIsplay Different Category Menu for Different Category"
- tuscanidream on "Changed front page and post pages, now ?cat=0 goes to the wrong page"