{"id":56078,"date":"2011-07-16T08:00:00","date_gmt":"2011-07-16T08:00:00","guid":{"rendered":"https:\/\/www.weixiaoduo.com\/plugins\/2024\/02\/22\/dropdown-menus\/"},"modified":"2013-01-17T02:15:00","modified_gmt":"2013-01-17T02:15:00","slug":"dropdown-menus","status":"publish","type":"post","link":"https:\/\/www.weixiaoduo.com\/plugins\/dropdown-menus\/","title":{"rendered":"Dropdown Menus"},"content":{"rendered":"<p>Sometimes for mobile design or more generally small-screen design it can be beneficial to save space by using a dropdown for your navigation.<\/p>\n<p>This plugin provides a way to display your custom menus as dropdowns either using a widget or a function call and can be used as an include in any theme.<\/p>\n<h4>Usage<\/h4>\n<p>If you are using the plugin with a theme you can use the function <code>dropdown_menu()<\/code> in place of calls to <code>wp_nav_menu()<\/code>.<\/p>\n<p>The <code>dropdown_menu()<\/code> function takes the same arguments as <code>wp_nav_menu()<\/code> with the addition of three extras:<\/p>\n<pre><code><?php\ndropdown_menu( array(\n\n    \/\/ You can alter the blanking text eg. \"- Menu Name -\" using the following\n    'dropdown_title' => '-- Main Menu --',\n\n    \/\/ indent_string is a string that gets output before the title of a\n    \/\/ sub-menu item. It is repeated twice for sub-sub-menu items and so on\n    'indent_string' => '- ',\n\n    \/\/ indent_after is an optional string to output after the indent_string\n    \/\/ if the item is a sub-menu item\n    'indent_after' => ''\n\n) );\n?>\n<\/code><\/pre>\n<p>You can extend and alter the output of the dropdowns using the output filters available in the code.<\/p>\n<p>There are also plenty of styling hooks like in the standard list type menus with the addition of classes for targetting items at a certain depth in the menu (<code>.menu-item-depth-1<\/code> for example) aswell the usual <code>.current-menu-item<\/code> and <code>.current-menu-ancestor<\/code> classes.<\/p>\n<h4>Filters\/Hooks<\/h4>\n<p><strong>dropdown_blank_item_text<\/strong><\/p>\n<pre><code><?php\nadd_filter( 'dropdown_blank_item_text', 10, 2 );\nfunction my_dropdown_blank_text( $title, $args ) {\n    return __( '- Browse -' );\n}\n?>\n<\/code><\/pre>\n<p>If you want to show the menu title as the blank item text use the follwing code:<\/p>\n<pre><code><?php\nadd_filter( 'dropdown_blank_item_text', 'dropdown_menu_use_menu_title', 10, 2 );\nfunction dropdown_menu_use_menu_title( $title, $args ) {\n    return '- ' . $args->menu->name . ' -';\n}\n?>\n<\/code><\/pre>\n<p><strong>dropdown_menus_indent_string<\/strong><\/p>\n<pre><code><?php\nadd_filter( 'dropdown_menus_indent_string', 10, 4 );\nfunction my_dropdown_indent_string( $indent_string, $item, $depth, $args ) {\n    return str_repeat( '&nbsp;&nbsp;', $depth );\n}\n?>\n<\/code><\/pre>\n<p><strong>dropdown_menus_indent_after<\/strong><\/p>\n<pre><code><?php\nadd_filter( 'dropdown_menus_indent_after', 10, 4 );\nfunction my_dropdown_indent_after( $indent_after, $item, $depth, $args ) {\n    return '-';\n}\n?>\n<\/code><\/pre>\n<p><strong>dropdown_menus_class<\/strong><\/p>\n<p>Use this if you find you get class name or CSS conflicts, for example with Twitter Bootstrap.<\/p>\n<pre><code><?php\nadd_filter( 'dropdown_menus_class', create_function( '$c', 'return \"my-dropdown-menu-class\";' ) );\n?>\n<\/code><\/pre>\n<p><strong>dropdown_menus_select_current<\/strong><\/p>\n<p>Use this filter to stop the output of the <code>selected=\"selected\"<\/code> attribute. Useful if you prefer to show the blank option on every page.<\/p>\n<pre><code><?php\nadd_filter( 'dropdown_menus_select_current', create_function( '$bool', 'return false;' ) );\n?>\n<\/code><\/pre>\n<h4>Can I make sure this plugin is available to my theme?<\/h4>\n<p>If your theme requires this plugin to be available it will work as a simple include. Just place the plugin into your theme directory and include dropdown-menus.php from your functions.php file.<\/p>\n<p>If you place the plugin folder into your theme\u2019s directory you would use the following code in your functions.php file:<\/p>\n<pre><code><?php\nif ( ! function_exists( 'dropdown_menu' ) )\n    include( 'dropdown-menus\/dropdown-menus.php' );\n?>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Display your WordPress menus as a dropdown select box. Great for mobile designs.<\/p>\n","protected":false},"author":65,"featured_media":266900,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Dropdown Menus - \u8587\u6653\u6735\u63d2\u4ef6\u76ee\u5f55","description":"Display your WordPress menus as a dropdown select box. Great for mobile designs."},"footnotes":""},"categories":[1],"tags":[4098,1138,1045,978,2539],"class_list":["post-56078","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-dropdowns","tag-menus","tag-mobile","tag-navigation","tag-ui"],"_links":{"self":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/56078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/comments?post=56078"}],"version-history":[{"count":0,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/56078\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media\/266900"}],"wp:attachment":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media?parent=56078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/categories?post=56078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/tags?post=56078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}