AI助手支持GPT4.0
This plugin provides an API which allows the developer of a site to add custom fields on the default menu editor.
此插件提供了一个API,该API允许网站的开发人员在默认菜单编辑器上添加自定义字段。 p>
<?phpadd_action('init', 'menu_excerpt__add_menu_field');add_action('init','menu_excerpt__add_menu_field');function menu_excerpt__add_menu_field() { 函数menu_excerpt__add_menu_field(){ if (!is_callable('bh_add_custom_menu_fields')) 如果(!is_callable('bh_add_custom_menu_fields')) return; 返回; bh_add_custom_menu_fields(array( bh_add_custom_menu_fields(array( 'excerpt' => array( '摘录'=>数组( 'description' => 'Excerpt', '描述'=>'摘录', 'type' => 'textarea', 'type'=>'textarea', )));)));}}?>?> code> pre>Accessing the fields访问字段 h4>The easiest way to access the field(s) you’ve added is to use something along the lines of:访问您添加的字段的最简单方法是使用类似于以下内容的内容: p>$menu = 'menuName'; $ menu ='menuName';$posts = wp_get_nav_menu_items($menu);$ posts = wp_get_nav_menu_items($ menu);foreach ($posts as $p) { foreach($ posts as $ p){ $myitem = get_post_meta($p->ID, '_menu_item_youritem', true); $ myitem = get_post_meta($ p-> ID,'_menu_item_youritem',true); // do with $myitem what you like - it should be a string, //用$ myitem做你喜欢的-它应该是一个字符串, // so the simplest thing is to "echo" it//因此,最简单的方法是“回显”它}} code> pre>you can use menu locations to get the menu name if you prefer – replace the first line above with:如果愿意,可以使用菜单位置获取菜单名称-将上面的第一行替换为: p>$locations = get_nav_menu_locations(); $ locations = get_nav_menu_locations();$menu = $locations['locationName'];$ menu = $ locations ['locationName']; code> pre>menu locations are useful if you like to swap your menus about.如果想要交换菜单,菜单位置会很有用。 p>Unfortunately these examples don’t allow the use of wordpress’ inbuilt menu walkers.不幸的是,这些示例不允许使用wordpress的内置菜单浏览器。To use those you will need to create a custom walker_nav_menu class and access the custom fields with something along the lines of (very stripped down example will need fleshing out for full walker functionality – there are tutorials on the net for custom nav walkers):<要使用这些功能,您将需要创建一个自定义的walker_nav_menu类,并使用类似于的内容访问自定义字段(非常简单的示例将需要充实才能获得完整的沃克功能-网上有自定义导航沃克的教程):< /p>/ p>class mywalker extends Walker_Nav_Menu { class mywalker扩展了Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { 函数start_el(&$ output,$ item,$ depth,$ args){ echo $item->custom_field 回声$ item-> custom_field }}}} code> pre>The important bit here is that the field is placed on the second variable which behaves like an object.这里重要的一点是,该字段位于行为类似于对象的第二个变量上。 the custom_field part is the name you gave your field with dashes replaced with underscores (to allow the name to be used in an accessor).custom_field部分是您为字段指定的名称,并用短划线代替了下划线(以便在访问器中使用该名称)。 p>NOTE注意 h4>This plugin does nothing by itself.此插件本身不执行任何操作。It provides an API only.它仅提供API。 p>
<?phpadd_action('init', 'menu_excerpt__add_menu_field');add_action('init','menu_excerpt__add_menu_field');function menu_excerpt__add_menu_field() { 函数menu_excerpt__add_menu_field(){ if (!is_callable('bh_add_custom_menu_fields')) 如果(!is_callable('bh_add_custom_menu_fields')) return; 返回; bh_add_custom_menu_fields(array( bh_add_custom_menu_fields(array( 'excerpt' => array( '摘录'=>数组( 'description' => 'Excerpt', '描述'=>'摘录', 'type' => 'textarea', 'type'=>'textarea', )));)));}}?>?>
add_action('init', 'menu_excerpt__add_menu_field');
add_action('init','menu_excerpt__add_menu_field');
function menu_excerpt__add_menu_field() {
函数menu_excerpt__add_menu_field(){
if (!is_callable('bh_add_custom_menu_fields'))
如果(!is_callable('bh_add_custom_menu_fields'))
return;
返回;
bh_add_custom_menu_fields(array(
bh_add_custom_menu_fields(array(
'excerpt' => array(
'摘录'=>数组(
'description' => 'Excerpt',
'描述'=>'摘录',
'type' => 'textarea',
'type'=>'textarea',
)));
)));
}
?>
?>
code> pre>
The easiest way to access the field(s) you’ve added is to use something along the lines of:
访问您添加的字段的最简单方法是使用类似于以下内容的内容: p>
$menu = 'menuName'; $ menu ='menuName';$posts = wp_get_nav_menu_items($menu);$ posts = wp_get_nav_menu_items($ menu);foreach ($posts as $p) { foreach($ posts as $ p){ $myitem = get_post_meta($p->ID, '_menu_item_youritem', true); $ myitem = get_post_meta($ p-> ID,'_menu_item_youritem',true); // do with $myitem what you like - it should be a string, //用$ myitem做你喜欢的-它应该是一个字符串, // so the simplest thing is to "echo" it//因此,最简单的方法是“回显”它}} code> pre>you can use menu locations to get the menu name if you prefer – replace the first line above with:如果愿意,可以使用菜单位置获取菜单名称-将上面的第一行替换为: p>$locations = get_nav_menu_locations(); $ locations = get_nav_menu_locations();$menu = $locations['locationName'];$ menu = $ locations ['locationName']; code> pre>menu locations are useful if you like to swap your menus about.如果想要交换菜单,菜单位置会很有用。 p>Unfortunately these examples don’t allow the use of wordpress’ inbuilt menu walkers.不幸的是,这些示例不允许使用wordpress的内置菜单浏览器。To use those you will need to create a custom walker_nav_menu class and access the custom fields with something along the lines of (very stripped down example will need fleshing out for full walker functionality – there are tutorials on the net for custom nav walkers):<要使用这些功能,您将需要创建一个自定义的walker_nav_menu类,并使用类似于的内容访问自定义字段(非常简单的示例将需要充实才能获得完整的沃克功能-网上有自定义导航沃克的教程):< /p>/ p>class mywalker extends Walker_Nav_Menu { class mywalker扩展了Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { 函数start_el(&$ output,$ item,$ depth,$ args){ echo $item->custom_field 回声$ item-> custom_field }}}} code> pre>The important bit here is that the field is placed on the second variable which behaves like an object.这里重要的一点是,该字段位于行为类似于对象的第二个变量上。 the custom_field part is the name you gave your field with dashes replaced with underscores (to allow the name to be used in an accessor).custom_field部分是您为字段指定的名称,并用短划线代替了下划线(以便在访问器中使用该名称)。 p>NOTE注意 h4>This plugin does nothing by itself.此插件本身不执行任何操作。It provides an API only.它仅提供API。 p>
$ menu ='menuName';$posts = wp_get_nav_menu_items($menu);$ posts = wp_get_nav_menu_items($ menu);foreach ($posts as $p) { foreach($ posts as $ p){ $myitem = get_post_meta($p->ID, '_menu_item_youritem', true); $ myitem = get_post_meta($ p-> ID,'_menu_item_youritem',true); // do with $myitem what you like - it should be a string, //用$ myitem做你喜欢的-它应该是一个字符串, // so the simplest thing is to "echo" it//因此,最简单的方法是“回显”它}}
$posts = wp_get_nav_menu_items($menu);
$ posts = wp_get_nav_menu_items($ menu);
foreach ($posts as $p) {
foreach($ posts as $ p){
$myitem = get_post_meta($p->ID, '_menu_item_youritem', true);
$ myitem = get_post_meta($ p-> ID,'_menu_item_youritem',true);
// do with $myitem what you like - it should be a string,
//用$ myitem做你喜欢的-它应该是一个字符串,
// so the simplest thing is to "echo" it
//因此,最简单的方法是“回显”它
you can use menu locations to get the menu name if you prefer – replace the first line above with:
如果愿意,可以使用菜单位置获取菜单名称-将上面的第一行替换为: p>
$locations = get_nav_menu_locations(); $ locations = get_nav_menu_locations();$menu = $locations['locationName'];$ menu = $ locations ['locationName']; code> pre>menu locations are useful if you like to swap your menus about.如果想要交换菜单,菜单位置会很有用。 p>Unfortunately these examples don’t allow the use of wordpress’ inbuilt menu walkers.不幸的是,这些示例不允许使用wordpress的内置菜单浏览器。To use those you will need to create a custom walker_nav_menu class and access the custom fields with something along the lines of (very stripped down example will need fleshing out for full walker functionality – there are tutorials on the net for custom nav walkers):<要使用这些功能,您将需要创建一个自定义的walker_nav_menu类,并使用类似于的内容访问自定义字段(非常简单的示例将需要充实才能获得完整的沃克功能-网上有自定义导航沃克的教程):< /p>/ p>class mywalker extends Walker_Nav_Menu { class mywalker扩展了Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { 函数start_el(&$ output,$ item,$ depth,$ args){ echo $item->custom_field 回声$ item-> custom_field }}}} code> pre>The important bit here is that the field is placed on the second variable which behaves like an object.这里重要的一点是,该字段位于行为类似于对象的第二个变量上。 the custom_field part is the name you gave your field with dashes replaced with underscores (to allow the name to be used in an accessor).custom_field部分是您为字段指定的名称,并用短划线代替了下划线(以便在访问器中使用该名称)。 p>NOTE注意 h4>This plugin does nothing by itself.此插件本身不执行任何操作。It provides an API only.它仅提供API。 p>
$ locations = get_nav_menu_locations();$menu = $locations['locationName'];$ menu = $ locations ['locationName'];
$menu = $locations['locationName'];
$ menu = $ locations ['locationName'];
menu locations are useful if you like to swap your menus about.
如果想要交换菜单,
菜单位置会很有用。 p>
Unfortunately these examples don’t allow the use of wordpress’ inbuilt menu walkers.
不幸的是,这些示例不允许使用wordpress的内置菜单浏览器。
To use those you will need to create a custom walker_nav_menu class and access the custom fields with something along the lines of (very stripped down example will need fleshing out for full walker functionality – there are tutorials on the net for custom nav walkers):<
要使用这些功能,您将需要创建一个自定义的walker_nav_menu类,并使用类似于的内容访问自定义字段(非常简单的示例将需要充实才能获得完整的沃克功能-网上有自定义导航沃克的教程):<
/p>
/ p>
class mywalker extends Walker_Nav_Menu { class mywalker扩展了Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { 函数start_el(&$ output,$ item,$ depth,$ args){ echo $item->custom_field 回声$ item-> custom_field }}}} code> pre>The important bit here is that the field is placed on the second variable which behaves like an object.这里重要的一点是,该字段位于行为类似于对象的第二个变量上。 the custom_field part is the name you gave your field with dashes replaced with underscores (to allow the name to be used in an accessor).custom_field部分是您为字段指定的名称,并用短划线代替了下划线(以便在访问器中使用该名称)。 p>NOTE注意 h4>This plugin does nothing by itself.此插件本身不执行任何操作。It provides an API only.它仅提供API。 p>
class mywalker扩展了Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { 函数start_el(&$ output,$ item,$ depth,$ args){ echo $item->custom_field 回声$ item-> custom_field }}}}
function start_el(&$output, $item, $depth, $args) {
函数start_el(&$ output,$ item,$ depth,$ args){
echo $item->custom_field
回声$ item-> custom_field
The important bit here is that the field is placed on the second variable which behaves like an object.
这里重要的一点是,该字段位于行为类似于对象的第二个变量上。
the custom_field part is the name you gave your field with dashes replaced with underscores (to allow the name to be used in an accessor).
custom_field部分是您为字段指定的名称,并用短划线代替了下划线(以便在访问器中使用该名称)。 p>
This plugin does nothing by itself.
此插件本身不执行任何操作。
It provides an API only.
它仅提供API。 p>
This section describes how to install the plugin and get it working.
本节介绍如何安装插件并使其正常工作。 p>
/wp-content/plugins/
/ wp-content / plugins / code>目录 li>Activate the plugin through the ‘Plugins’ menu in WordPress通过WordPress中的“插件”菜单激活插件 li>Once activated the API is available in the ‘init’ and later phases of the WordPress lifecycle.一旦激活,API就会在WordPress生命周期的“初始”阶段和更高阶段可用。 li>
ol>
原文出处:http://www.sanshu.cn/a/9624.html
群主管理都是支付大佬