Wordpress菜单问题

时间:2014-07-02 12:21:45

标签: php wordpress-plugin wordpress

有人可以通过我的Wordpress菜单帮助我创建一个自定义插件吗?

        // Add the menu, only for administrators            
        public function add_menu(){
            if(is_admin()){
                add_menu_page(__('EM Collaboration Main Page', 'em-collaboration'), 
                                  __('EM Collaboration', 'em-collaboration'), 
                                  'manage_options', 
                                  'em-collaboration/em-main.php', 
                                  '', '', 21);
                add_submenu_page('em-collaboration/em-main.php', 
                                      __('EM Collaboration Main Page', 'em-collaboration'), 
                                      __('All Collab Groups', 'em-collaboration'), 
                                      'manage_options', 
                                      'em-collaboration/em-main.php');
            }
        }

子菜单由于某种原因没有显示,我真的不确定为什么会这样...... 我查看了手抄本,从我看到它应该显示......

更新

        // Add the menu, only for administrators            
        public function add_menu(){
            if(is_admin()){
                add_menu_page(__('EM Collaboration All Groups', 'em-collaboration'), 
                                  __('EM Collaboration', 'em-collaboration'), 
                                  'manage_options',
                                  'em-collab-top', 
                                  'em-collaboration/em-main.php', 
                                  '', 
                                  21);
                add_submenu_page('em-collab-top', 
                                      __('EM Collaboration Settings', 'em-collaboration'), 
                                      __('Settings', 'em-collaboration'), 
                                      'manage_options', 
                                      'em-collaboration/em-settings.php');
            }
        }

1 个答案:

答案 0 :(得分:1)

问题是menu_slug。它是'manage_options'背后的参数。您为菜单和子菜单选择了“em-collaboration / em-main.php”。参考文献说,如果两者相同,菜单点将不会重复。

add_submenu_page

所以你的代码必须看起来像:

public function add_menu(){
        if(is_admin()){
            add_menu_page(__('EM Collaboration Main Page', 'em-collaboration'), 
                              __('EM Collaboration', 'em-collaboration'), 
                              'manage_options', 
                              '<the_menu_slug>', 
                              '', '', 21);
            add_submenu_page('em-collaboration/em-main.php', 
                                  __('EM Collaboration Main Page', 'em-collaboration'), 
                                  __('All Collab Groups', 'em-collaboration'), 
                                  'manage_options', 
                                  '<the_submenu_slug>');
        }
    }

“the_menu_slug”和“the_submenu_slug”需要不同才能显示子菜单。这个slugs不需要是文件的名称。它只是菜单项的别名。