Site icon Eric Juden

WordPress 3.0 and Menu Dropdown Box

I’ve started to play around with WordPress 3.0 Beta 2 and the new menu system it has. While playing around with it, I thought it might be nice to include a dropdown box of menu choices on a settings page for a theme. So I made a function similar to that of the dropdown box for categories (wp_dropdown_categories). I called this one wp_dropdown_nav_menus.

function wp_dropdown_nav_menus($args = ''){
	$defaults = array(
		'echo' => 1,
		'id' => '',
		'orderby' => 'name',
		'order' => 'ASC',
		'hide_empty' => 1,
		'selected' => 0,
		'class' => 'postform',
		'tab_index' => 0,
		'show_option_all' => '',
		'show_option_none' => '',
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r );

	$tab_index_attribute = '';
	if ( (int) $tab_index > 0 )
		$tab_index_attribute = " tabindex="$tab_index"";

	$terms = get_terms( 'nav_menu', array( 'hide_empty' => $r['hide_if_empty'], 'orderby' => $r['orderby'], 'order' => $r['order'] ));

	if(! empty($terms)){
		$output = "";
	}

	if ($echo){
		echo $output;
	}

	return $output;
}

If you want to use this in your code, please change the prefix of the function from wp_ to something more useful for your purpose. Just in case WordPress comes out with a function similar to this one.

Exit mobile version