如何添加子菜单到WordPress管理栏 [英] How can I add a Submenu to the WordPress Admin Bar

查看:116
本文介绍了如何添加子菜单到WordPress管理栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在管理栏中为Wordpress添加一个下拉菜单,以包含多个链接。什么是最好的解决方案?

I need to add a dropdown menu to Wordpress in the admin bar to include multiple links. What is the best solution?

推荐答案

我正在寻找这个问题的答案一段时间,找不到解决方案在这里,所以我以为这将有所帮助!我发现了一个很棒的博客文章和完美的解决方案,我的问题:

I was looking for the answer to this question for a while and couldn't find the solution on here so I thought this would help! I found a great blog post and the perfect solution to my question:

http://davidwalsh.name/add-submenu-wordpress-admin-bar

喜欢为您的主题添加功能和其他管理区域,指令将进入您的主题的functions.php文件。代码本身应该是自明的:

Like adding functionality to your theme and other admin area, the directives will go in your theme's functions.php file. The code itself should be self explanatory:

function create_dwb_menu() {
    global $wp_admin_bar;

    $menu_id = 'dwb';
    $wp_admin_bar->add_menu(array('id' => $menu_id, 'title' => __('DWB'), 'href' => '/'));
    $wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Homepage'), 'id' => 'dwb-home', 'href' => '/', 'meta' => array('target' => '_blank')));
    $wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Drafts'), 'id' => 'dwb-drafts', 'href' => 'edit.php?post_status=draft&post_type=post'));
    $wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Pending Comments'), 'id' => 'dwb-pending', 'href' => 'edit-comments.php?comment_status=moderated'));
}
add_action('admin_bar_menu', 'create_dwb_menu', 2000);

在父菜单项上设置一个ID可以让您使用父键进行子菜单项;其余的键很容易弄清楚。创建菜单后,您只需要添加WordPress钩子和特殊性即可添加!

Setting an id on the parent menu item allows you to use the parent key for submenu items; the rest of the keys are easy to figure out. With the menu created, you simply need to add the WordPress hook and specificity to add it!

这篇关于如何添加子菜单到WordPress管理栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆