管理菜单-在子菜单页面上突出显示顶级菜单(不显示子菜单)
-
-
参见:http://wordpress.stackexchange.com/a/105370/21376See: http://wordpress.stackexchange.com/a/105370/21376
- 0
- 2013-08-30
- s_ha_dum
-
不幸的是,该方法似乎与[remove_submenu_page](http://codex.wordpress.org/remove_submenu_page)相似,并且使访问该页面时抛出"您没有足够权限来访问此页面".信息.不过,我会进一步检查.谢谢你的建议.Unfortunately, that method seems to work similar to [remove_submenu_page](http://codex.wordpress.org/remove_submenu_page) and makes accessing the page throw a "You do not have sufficient permissions to access this page." message. I'll check up further on it though. Thanks for the suggestion.
- 0
- 2013-09-02
- Jayawi Perera
-
您主页上的选项卡式界面会达到相同的目标吗?http://getbutterfly.com/how-to-create-a-tabbed-interface-for-your-wordpress-plugin/Would a tabbed interface within your main page achieve the same goal? http://getbutterfly.com/how-to-create-a-tabbed-interface-for-your-wordpress-plugin/
- 2
- 2013-09-03
- epilektric
-
这是一个有趣的方法.我不确定我是否要在选项卡中加载所有不同的页面(总共大约8个左右).我想我可以做一些AJAX加载,在需要的时候加载单个页面的内容.我仍然有兴趣为原始问题找到解决方案.但是,我认为如果不修改核心文件(我不希望这样做),当前的WP版本可能是不可能的.我将检查选项卡式方法.谢谢你的建议.That's an interesting approach. I'm not entirely sure I want to have all the different pages (there are about 8 or so in total) loading in tabs though. I suppose I could do some AJAX loading where the individual page content is loaded as and when it is needed. I'm still interested in finding a solution for the original problem. However, I think it may not be possible for the current WP version without modifying the core files (which I do not wish to do). I'll check out the tabbed approach. Thanks for the suggestion.
- 0
- 2013-09-04
- Jayawi Perera
-
这里有一种简单的解决方法:https://wordpress.org/support/topic/no-page-menu-item/There's an easy way to resolve it here: https://wordpress.org/support/topic/no-page-menu-item/
- 0
- 2019-12-20
- Tsage
-
1 个回答
- 投票数
-
- 2014-09-20
这是一个较晚的答案,我不知道@Jay是否曾经解决过这个问题,但是对于有相同问题的任何人,这就是我的解决方法.
菜单页面
function my_admin_menu() { add_menu_page( 'Page title', 'Menu title', 'manage_options', 'my_page', null, null, 99 ); add_submenu_page( 'my_page', 'Subpage 1 title', 'Subpage 1 menu title', 'manage_options', 'my_subpage_1', null ); add_submenu_page( 'my_page', 'Subpage 2 title', 'Subpage 2 menu title', 'manage_options', 'my_subpage_2', null ); } add_action( 'admin_menu', 'my_admin_menu' ) ); function my_admin_head() { remove_submenu_page( 'my_page', 'my_subpage_1' ); } add_action( 'admin_head', 'my_admin_head' );
有关删除_submenu_page ,请参见法典.
That's a bit of a late answer and I don't know if @Jay ever sorted it out, but to anyone having the same issue, here's how I fixed it.
Menu Pages
function my_admin_menu() { add_menu_page( 'Page title', 'Menu title', 'manage_options', 'my_page', null, null, 99 ); add_submenu_page( 'my_page', 'Subpage 1 title', 'Subpage 1 menu title', 'manage_options', 'my_subpage_1', null ); add_submenu_page( 'my_page', 'Subpage 2 title', 'Subpage 2 menu title', 'manage_options', 'my_subpage_2', null ); } add_action( 'admin_menu', 'my_admin_menu' ) ); function my_admin_head() { remove_submenu_page( 'my_page', 'my_subpage_1' ); } add_action( 'admin_head', 'my_admin_head' );
See the Codex for remove_submenu_page.
这是当前情况:
我的要求是执行以下操作:
我尝试给子菜单页面添加父子弹.当然,这会使它按预期显示在顶级菜单项下.然后,我尝试使用remove_submenu_page删除子菜单项.但是,由于这会删除整个子菜单页面,因此无法解决问题.
我相信这样做是合乎逻辑的,因为顶层菜单项将需要知道所访问的页面位于该菜单项之下,这是给父级附加项的原因.然后,问题是没有显示子菜单页面的菜单项.我找不到直接处理菜单项的功能.
这是正确的方法还是有更好的选择? 我可以利用动作/过滤器/挂钩执行我需要做的事情吗?
编辑#1:
做过一些进一步的研究/测试.在add_submenu_page调用中将menu_title参数设置为null或"可使标题不显示.但是,< li>包含子菜单项的菜单仍然存在,并且可以与之交互.当有很多子菜单页面时(如我的情况),空白的< li>元素将加起来并在菜单上创建一个长长的空白区域.这远非理想,因此,我仍在寻找解决方案.
编辑#2: 在@s_ha_dum发表评论后,尝试操纵$ submenu全局变量.但是,任何与页面有关的菜单部分的删除也会导致类似于remove_submenu_page的页面删除,从而使该页面无法访问.