需要自定义wootemes画布中的顶部菜单,这取决于用户是否登录,我需要显示一个菜单而不是另一个


Need to customize the top menu in woothemes canvas, depending if the user is logged in or not I need to show 1 menu instead of the other

我已经创建了一个画布子主题。我在canvas子文件夹中添加了我的自定义页面woo-霍克s.class.php,我在其中复制了原始文件中的所有代码,并在此处添加:

$this->hooks['header'] = array(
        'woo_top' => array(
        'content' => '',
        'shortcodes' => 0,
        'php' =>'      

以下代码:

if ( is_user_logged_in() ) {
        wp_nav_menu( array( "theme_location" => "top-menu-loggedin" ) );
} else {
    wp_nav_menu( array( "theme_location" => "top-menu-loggedout" ) );
}   

代码好像根本不存在,我知道我可能弄错了我必须做的事情,但我在任何地方都找不到关于如何做到这一点的明确指南,只是一些论坛中的一些代码,没有关于如何以及在哪里操作的上下文(我添加的代码是在论坛中找到的,但我想我没有在正确的地方添加)。WP的过滤器和钩子指南没有明确在哪里和如何调用自定义过滤器和钩子,以及如何使它们与现有代码交互。。。我快疯了,请帮帮我。

顶部菜单自定义可以在标题部分执行,即在子主题的"header.php"文件中或在其他文件中执行,指定"主题位置"参数。

你可以写下面的代码,在你的孩子主题,

if (is_user_logged_in()){
   wp_nav_menu(array( 
  'menu_class' => 'member-menu',
  'menu'  => 'Members',
  'theme_location'  => 'primary');
   );
}else{
      wp_nav_menu(array( 
     'menu_class' => 'top-menu',
     'menu'  => 'Members non Logged in',
     'theme_location'  => 'primary')
     );
 }

这里,"主题位置"参数指定菜单的位置,"菜单"指定菜单的名称。