一,添加顶级菜单:
添加方法:
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
- $page_title:(字符串) (必须) 这个参数是子菜单的标题,将会显示在浏览器的标题栏,默认为空;
- $menu_title:(字符串) (必须) 显示的菜单名称,默认为空;
- $capability:(字符串) (必须) 用户权限,定义了具有哪些权限的用户会看到这个子菜单(权限部分请看文章结尾处),默认为空,参照capability;
- $menu_slug:(字符串) (必须) 显示在URl上面的菜单名称,默认为空;
- $function:返回的方法名称;
- $icon_url:(字符串) (可选) 显示的菜单图标,可以使用plugin_dir_url( __FILE__ ),图标宽高为16像素;
- $position:(整数) (可选) 显示菜单的位置。常用位置,4或者59或者99。
例子:
在模板的functions.php添加以下代码:
function add_advertise_pages() {
$icon_url=’http://www.luckybird.me/wp-content/uploads/2015/09/443e2d96c5201124216c443c4ec48716.jpg’;
add_menu_page(‘Advertise’, ‘Advertise’, ‘administrator’, ‘advertise’, ‘advertise_toplevel_page’,$icon_url,50);
}
function advertise_toplevel_page() {
echo ‘advertise’;
}
add_action(‘admin_menu’, ‘add_advertise_pages’);
2,添加子菜单
方法:
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
$parent_slug
这个参数为WordPress内置菜单的文件名称或缩略名,这里我们通常采用菜单文件名的方式。传递这个参数,就说明要往这个顶级菜单添加子菜 单,以上示例代码中传递的值为 tools.php ,对应工具顶级菜单,下面提供这个参数的所有值及其对应的顶级菜单:
- index.php:控制板
- edit.php:文章
- upload.php:媒体
- link-manager.php:链接
- edit.php?post_type=page:页面
- edit-comments.php:评论
- themes.php:主题
- plugins.php:插件
- users.php:用户
- tools.php:工具
- options-general.php:设置
$page_title
这个参数是子菜单的标题,将会显示在浏览器的标题栏。
$menu_title
这个是子菜单的名称,将会显示在侧边栏
$capability
用户权限,这个定义了具有哪些权限的用户会看到这个子菜单,具体的参数值,可以参考上面第一部分的顶级菜单的说明。
$menu_slug
子菜单的缩略名,请使用一个唯一的名称,英文形式。
$function
所有调用的函数名称,通过调用这个函数来显示这个子菜单页面的内容
例子:
function add_advertise_qr_submenu() {
add_submenu_page( ‘advertise’, ‘QR’, ‘All QR’, ‘administrator’, ‘advertise-QR’, ‘advertise_qr_submenu’);
}
function advertise_qr_submenu() {
echo ‘All QR’;
}
add_action(‘admin_menu’, ‘add_advertise_qr_submenu’);
3,效果图

Оптимизаторы, сделал бесплатный каталог статей. Интересно будет для всех, кто продвигает сайты в поисковиках при помощи статей с ссылками. Отправляйте свои статьи с ссылками на почту указанную в каталоге, и я размещу их на сайте. Все статьи проходят проверку на уникальность. Никаких линкопомоек!
http://www.catalogueofarticles.com/
hOur site offers a wide variety of non prescription drugs. Take a look at our health website in case you want to feel better with a help of generic supplements. Our company provides a wide variety of non prescription products. Visit our health website in case you want to to improve your health with a help of health products. Our company offers a wide variety of non prescription drugs. Visit our health website in case you want to to improve your health with a help of generic supplements. Our company offers a wide variety of non prescription products. Take a look at our health site in case you want to strengthen your health with a help of general health products. Our company provides supreme quality health products. Look at our health contributing portal in case you want to strengthen your health. Our company offers herbal pills. Look at our health contributing site in case you want to look healthier.
Our company provides a wide variety of non prescription products. Visit our health site in case you want to look better with a help general health products. Our company provides herbal pills. Take a look at our health contributing site in case you want to feel better. Our company provides a wide variety of non prescription drugs. Look at our health portal in case you want to look better with a help health products. Our company offers a wide variety of non prescription products. Take a look at our health site in case you want to look better with a help generic supplements. Our company provides a wide variety of non prescription drugs. Look at our health portal in case you want to feel better with a help of generic supplements.