我只是为我正在工作的一个网站做这件事。首先,我在函数中注册了2个菜单。php:
add_action(\'init\',\'kia_menus\');
function kia_menus(){
register_nav_menus( array(\'primary-menu\' => __( \'Primary Menu for Logged In Users\', \'kia_theme\' ),
\'primary-loggedout\' => __( \'Primary Menu for Logged Out Visitors\', \'kia_theme\')
));
}
然后,我希望根据用户的状态显示1菜单的位置(可能在header.php中,但取决于您的主题):
if( !is_user_logged_in() ){
wp_nav_menu( array( \'theme_location\' => \'primary-loggedout\' ) );
} else {
wp_nav_menu( array( \'theme_location\' => \'primary-menu\' ) );
}