您的位置:首页 > 其它

wordpress后台添加菜单的函数集合

2015-03-18 00:16 423 查看
添加子菜单,具体的说在WordPress后台侧边栏上在每一个顶级菜单中添加一个子菜单,或者独立添加到指定的顶级菜单中去。

函数的用法:

<?php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability,$menu_slug, $function );?>

参数说明:

$parent_slug


(字符串) (必须)顶级菜单名称,可以在顶级菜单中加入我们的子菜单,也可以在自定义顶级菜单中加入子菜单。

$page_title


(字符串) (必须) 当点击菜单后将内容显示在标题标签上(Title Tag于浏览器上),默认为空。

$menu_title


(字符串) (必须) 显示的菜单名称,默认为空。

$capability


(字符串) (必须) 此菜单使用的权限,默认为空,参照capability

$menu_slug


(字符串) (必须) 显示在URl上面的菜单名称,默认为空。

$function

返回的方法名称

页面添加方法一览

1、在仪表盘添加子菜单: add_submenu_page( ‘index.php’, … );

2、在文章处添加子菜单: add_submenu_page( ‘edit.php’, … );

3、在媒体处添加子菜单: add_submenu_page( ‘upload.php’, … );

4、在链接处添加子菜单: add_submenu_page( ‘link-manager.php’, … );

5、在页面处添加子菜单: add_submenu_page( ‘edit.php?post_type=page’, … );

6、在评论处添加子菜单: add_submenu_page( ‘edit-comments.php’, … );

7、在你自定义文章类型处添加子菜单: add_submenu_page(‘edit.php?post_type=your_post_type’,…)

8、在外观处添加子菜单: add_submenu_page( ‘themes.php’, … );

9、在插件处添加子菜单: add_submenu_page( ‘plugins.php’, … );

10、在用户处添加子菜单: add_submenu_page( ‘users.php’, … );

11、在工具处添加子菜单: add_submenu_page( ‘tools.php’, … );

12、在设置处添加子菜单: add_submenu_page( ‘options-general.php’, … );

例子:

1.在单独使用的时候,将子菜单添加到工具(tools)顶级菜单中

add_action(‘admin_menu’, ‘register_my_custom_submenu_page’);

function register_my_custom_submenu_page() {

add_submenu_page( ‘tools.php’, ‘子菜单’, ‘子菜单名称’, ‘manage_options’, ‘my-custom-submenu-page’, ‘my_custom_submenu_page_callback’ );

}

function my_custom_submenu_page_callback() {

echo ‘<h3>我定义的内容</h3>';

}

2.在定义的顶级菜单中添加子菜单

function fengxl_admin_fstmenu()

{

add_menu_page(__(‘顶级菜单’),__(‘顶级菜单名称’),8,__FILE__,’my_function_menu’);

add_submenu_page(__FILE__,’子菜单1′,’子菜单名称1′,8,’your-admin-sub-menu1′,’my_function_submenu1′);

add_submenu_page(__FILE__,’子菜单2′,’子菜单名称2′,8,’your-admin-sub-menu2′,’my_function_submenu2′);

}

function my_function_menu()

{

echo “<h2>顶级菜单显示的内容</h2>”;

}

function my_function_submenu1()

{

echo “<h2>子菜单1显示的内容</h2>”;

}

function my_function_submenu2()

{

echo “<h2>子菜单2显示的内容</h2>”;

}

add_action(‘admin_menu’,’fengxl_admin_fstmenu’);

通过以上这个函数就可以在后台添加子菜单,可以用于插件中也可以用在主题的functions.php等其他地方。

本文固定链接: http://www.frontopen.com/1714.html
转载请注明: 品味人生 2013年12月19日 于 前端开拓者 发表
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: