[wordpress插件] Dropdown Menus下拉菜单

wordpress 插件 文章 2020-04-22 10:40 527 0 全屏看文

AI助手支持GPT4.0

评分
88
描述

Sometimes for mobile design or more generally small-screen design it can be beneficial to save space by using a dropdown for your navigation.

有时对于移动设计或更普遍的小屏幕设计,使用下拉菜单进行导航可以节省空间。

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.

此插件提供了一种使用小部件或函数调用将自定义菜单显示为下拉菜单的方法,并且可以用作任何主题中的包含项。

Usage

用法

If you are using the plugin with a theme you can use the function dropdown_menu() in place of calls to wp_nav_menu().

如果您使用具有主题的插件,则可以使用函数 dropdown_menu()代替对 wp_nav_menu()的调用。

The dropdown_menu() function takes the same arguments as wp_nav_menu() with the addition of three extras:

dropdown_menu()函数采用与 wp_nav_menu()相同的参数,并增加了三个附加功能:

  <?php

dropdown_menu( array(    

dropdown_menu(数组(    

// You can alter the blanking text eg.

//您可以更改空白文本,例如

"- Menu Name -" using the following    

“-菜单名称-”使用以下内容    

'dropdown_title' => '-- Main Menu --',    

'dropdown_title'=>'-主菜单-',    

// indent_string is a string that gets output before the title of a    

// indent_string是一个字符串,该字符串在a的标题之前输出    

// sub-menu item.

//子菜单项。

It is repeated twice for sub-sub-menu items and so on    

子菜单项重复两次,依此类推    

'indent_string' => '- ',    

'indent_string'=>'-',    

// indent_after is an optional string to output after the indent_string    

// indent_after是在indent_string之后输出的可选字符串    

// if the item is a sub-menu item    

//如果该项是子菜单项    

'indent_after' => ''

'indent_after'=>''

) );

));

?>

?>

You can extend and alter the output of the dropdowns using the output filters available in the code.

您可以使用代码中可用的输出过滤器来扩展和更改下拉菜单的输出。

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 (.menu-item-depth-1 for example

还有很多样式钩子,例如标准列表类型菜单中的样式钩子,以及在菜单中特定深度处定位项目的类(例如 .menu-item-depth-1

) aswell the usual .current-menu-item and .current-menu-ancestor classes.

)以及常用的 .current-menu-item .current-menu-ancestor 类。

Filters/Hooks

过滤器/挂钩

dropdown_blank_item_text

dropdown_blank_item_text

  <?php

add_filter( 'dropdown_blank_item_text', 10, 2 );

add_filter('dropdown_blank_item_text',10,2);

function my_dropdown_blank_text( $title, $args ) {    

函数my_dropdown_blank_text($ title,$ args){    

return __( '- Browse -' );

返回__('-');

}

}

?>

?>

If you want to show the menu title as the blank item text use the follwing code:

如果要将菜单标题显示为空白项目文本,请使用以下代码:

  <?php

add_filter( 'dropdown_blank_item_text', 'dropdown_menu_use_menu_title', 10, 2 );

add_filter('dropdown_blank_item_text','dropdown_menu_use_menu_title',10,2);

function dropdown_menu_use_menu_title( $title, $args ) {    

函数dropdown_menu_use_menu_title($ title,$ args){    

return '- ' .

返回'-'。

$args->menu->name .

$ args-> menu-> name。

' -';

'-';

}

}

?>

?>

dropdown_menus_indent_string

dropdown_menus_indent_string

  <?php

add_filter( 'dropdown_menus_indent_string', 10, 4 );

add_filter('dropdown_menus_indent_string',10,4);

function my_dropdown_indent_string( $indent_string, $item, $depth, $args ) {    

函数my_dropdown_indent_string($ indent_string,$ item,$ depth,$ args){    

return str_repeat( '  ', $depth );

return str_repeat('&nbsp;',$ depth);

}

}

?>

?>

dropdown_menus_indent_after

dropdown_menus_indent_after

  <?php

add_filter( 'dropdown_menus_indent_after', 10, 4 );

add_filter('dropdown_menus_indent_after',10,4);

function my_dropdown_indent_after( $indent_after, $item, $depth, $args ) {    

函数my_dropdown_indent_after($ indent_after,$ item,$ depth,$ args){    

return '-';

返回'-';

}

}

?>

?>

dropdown_menus_class

dropdown_menus_class

Use this if you find you get class name or CSS conflicts, for example with Twitter Bootstrap.

如果发现类名或CSS冲突(例如与Twitter Bootstrap)冲突,请使用此选项。

  <?php

add_filter( 'dropdown_menus_class', create_function( '$c', 'return "my-dropdown-menu-class";' ) );

add_filter('dropdown_menus_class',create_function('$ c','return“ my-dropdown-menu-class”;'));

?>

?>

dropdown_menus_select_current

dropdown_menus_select_current

Use this filter to stop the output of the selected="selected" attribute.

使用此过滤器停止 selected =“ selected” 属性的输出。

Useful if you prefer to show the blank option on every page.

如果希望在每个页面上显示空白选项,则很有用。

  <?php

add_filter( 'dropdown_menus_select_current', create_function( '$bool', 'return false;' ) );

add_filter('dropdown_menus_select_current',create_function('$ bool','return false;'));

?>

?>

Can I make sure this plugin is available to my theme?

我可以确保此插件可用于我的主题吗?

If your theme requires this plugin to be available it will work as a simple include.

如果您的主题要求此插件可用,它将作为简单的include起作用。

Just place the plugin into your theme directory and include dropdown-menus.php from your functions.php file.

只需将插件放入您的主题目录,并从functions.php文件中包含dropdown-menus.php。

If you place the plugin folder into your theme’s directory you would use the following code in your functions.php file:

如果将plugin文件夹放置在主题目录中,则可以在functions.php文件中使用以下代码:

  <?php

if ( ! function_exists( 'dropdown_menu' ) )    

如果(!function_exists('dropdown_menu'))    

include( 'dropdown-menus/dropdown-menus.php' );

include('dropdown-menus / dropdown-menus.php');

?>

?>

下载地址
https://downloads.wordpress.org/plugin/dropdown-menus.1.0.zip
-EOF-

AI助手支持GPT4.0