我试图显示仪表板的菜单,显示名称和与之关联的文件名,如下所示:
Dashboard > index.php
Posts > edit.php
Media > upload.php
etc...
这就是我目前使用global
$menu
要在仪表板上显示所有可用菜单项,请执行以下操作:
global $menu;
foreach ( $menu as $group => $item ) {
foreach ( $item as $label ) {
echo $label . " > " . $item[2] . "<br>";
}
echo "<br>";
}
然而,它给出了以下结果:
Dashboard > index.php
read > index.php
index.php > index.php
> index.php
menu-top menu-top-first menu-icon-dashboard menu-top-last > index.php
menu-dashboard > index.php
dashicons-dashboard > index.php
> separator1
read > separator1
separator1 > separator1
> separator1
wp-menu-separator > separator1
Posts > edit.php
edit_posts > edit.php
edit.php > edit.php
> edit.php
menu-top menu-icon-post open-if-no-js menu-top-first > edit.php
menu-posts > edit.php
dashicons-admin-post > edit.php
etc...
我知道我可以
Dashboard > index.php
但还有我不需要的额外信息。有什么建议我需要更改,只显示每个菜单的前两项吗?
最合适的回答,由SO网友:Rarst 整理而成
因为你没有涉及到这一部分,所以不确定你要准确地完成什么。
查看这些数据,我想您可以通过检查适当的标题来过滤掉分隔符等:
global $menu;
foreach ( $menu as $group => $item ) {
if ( ! empty( $item[0] ) ) {
echo $item[0] . " > " . $item[2] . "<br>";
}
}
我在以下方面的结果:
Dashboard > index.php
Posts > edit.php
Media > upload.php
Pages > edit.php?post_type=page
Comments 0 > edit-comments.php
Test > edit.php?post_type=test
Appearance > themes.php
Plugins 0 > plugins.php
Users > users.php
Tools > tools.php
Settings > options-general.php
SEO 00 notifications > wpseo_dashboard