我正在使用以下内容显示菜单
if ( has_nav_menu( \'topheader\' ) ) {
// User has assigned menu to this location;
// output it
wp_nav_menu( array(
\'theme_location\' => \'topheader\',
\'menu_class\' => \'topMenu\', /* bootstrap ul */
\'walker\' => new My_Walker_Nav_Menu(), /* changes to a bootstrap class */
\'items_wrap\' => \'<ul id="%1$s" class="%2$s">%3$s</ul>\',
\'menu_id\' => \'topMenu\'
) );
}
如果菜单中没有链接,则前端不会显示任何内容。是否可以显示添加菜单的链接?它将用户带到仪表板中的菜单位置。
最合适的回答,由SO网友:David Lee 整理而成
其可能:
if (has_nav_menu(\'topheader\')) {
// User has assigned menu to this location;
// output it
wp_nav_menu(array(
\'theme_location\' => \'topheader\',
\'menu_class\' => \'topMenu\', /* bootstrap ul */
\'walker\' => new My_Walker_Nav_Menu(), /* changes to a bootstrap class */
\'items_wrap\' => \'<ul id="%1$s" class="%2$s">%3$s</ul>\',
\'menu_id\' => \'topMenu\'
));
}else{
if (is_user_logged_in()) { //we check if the user is logged in
echo \'<a href="/wp-admin/nav-menus.php?action=edit&menu=0">Add New Menu</a>\';
}
}
这将打开菜单仪表板,准备创建新菜单。