wordpress后台添加菜单的函数集合
2015-03-18 00:16
423 查看
添加子菜单,具体的说在WordPress后台侧边栏上在每一个顶级菜单中添加一个子菜单,或者独立添加到指定的顶级菜单中去。
函数的用法:
<?php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability,$menu_slug, $function );?>
参数说明:
(字符串) (必须)顶级菜单名称,可以在顶级菜单中加入我们的子菜单,也可以在自定义顶级菜单中加入子菜单。
(字符串) (必须) 当点击菜单后将内容显示在标题标签上(Title Tag于浏览器上),默认为空。
(字符串) (必须) 显示的菜单名称,默认为空。
(字符串) (必须) 此菜单使用的权限,默认为空,参照capability
(字符串) (必须) 显示在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日 于 前端开拓者 发表
函数的用法:
<?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日 于 前端开拓者 发表
相关文章推荐
- 在WordPress的后台中添加顶级菜单和子菜单的函数详解
- 在WordPress的后台中添加顶级菜单和子菜单的函数详解
- WordPress后台添加侧边栏菜单
- 黄聪:WordPress后台添加侧边栏菜单(WP教程add_menu_page)
- 在WordPress后台菜单系统中添加Home链接
- 代码笔记:wordpress后台添加菜单的几种方式比较
- update_user_meta函数让wordpress后台添加usermeta的方法
- wordpress 想后台中的侧边栏添加菜单,子菜单
- wordpress添加后台菜单及权限设置
- WordPress后台添加侧边栏菜单
- wordpress后台侧边添加菜单
- 为主题添加多个WordPress3.0自定义菜单
- discuz后台主导航栏菜单中添加新的菜单项的方法
- wordpress添加顶级菜单
- WordPress后台删除不需要的侧边栏菜单
- C++中怎样将菜单添加到消息响应函数中去?
- 方维分享系统二次开发,给后台添加菜单
- WordPress 给导航栏添加非菜单栏目
- 主题实现后台添加顶级菜单和列出数据
- AppendMenu函数添加菜单