如何在主题上同时设置顶部和侧边栏菜单

时间:2018-06-20 05:26:49

标签: php html css wordpress

我有pluto wordpress theme。它有2个很棒的菜单,我想同时使用它们。
我会解释:
顶部菜单如下所示:

enter image description here

侧边栏菜单如下所示:

enter image description here

现在,我可以一次显示一个菜单。顶部或侧边栏菜单。 既然它们都不错,我想将它们结合起来并在我的站点中显示两个菜单,就像这样:

enter image description here

我认为通过设置该主题的 function.php 可以实现这一目标,因此我查找了一下,并在主题的 function.php 中找到了以下相关代码目录:

  // This theme uses wp_nav_menu() in two locations.
  register_nav_menus( array(
    'side_menu' => __( 'Main Menu', 'pluto' ),
    'footer' => esc_html__( 'Footer Menu', 'pluto' ),
  ) );

// Add specific CSS class by filter
add_filter('body_class','osetin_menu_body_class');
function osetin_menu_body_class($classes) {
  // add body class depending on menu position
  switch(get_current_menu_position()){
    case "top":
      $classes[] = 'menu-position-top';

      switch(get_current_menu_style()){
        case "v1":
          $classes[] = 'menu-style-v1';
        break;
        case "v2":
          $classes[] = 'menu-style-v2';
        break;
        default:
          $classes[] = 'menu-style-v2';
        break;
      }

    break;
    case "right":
      $classes[] = 'menu-position-right';
    break;
    default:
      $classes[] = 'menu-position-left';
    break;
  }
  if(is_home() 
    || is_page_template('page-photos.php') 
    || is_page_template('page-masonry.php') 
    || is_page_template('page-masonry-condensed.php') 
    || is_page_template('page-masonry-simple.php') 
    || is_page_template('page-masonry-condensed-facebook.php') 
    || is_page_template('page-masonry-simple-facebook.php') 
    || is_page_template('page-masonry-condensed-with-author.php') 
    || is_page_template('page-masonry-condensed-fixed-height.php') 
    || is_page_template('page-masonry-condensed-pinterest.php')
    || is_page_template('page-masonry-simple-pinterest.php')){

    // MASONRY PAGE - first check if we want to show a sidebar on masonry page
    if(os_get_show_sidebar_on_masonry() == true){
      // add body class depending on sidebar position
      switch(osetin_get_field('sidebar_position', 'option')){
        case "left":
          $classes[] = 'sidebar-position-left';
        break;
        case "right":
          $classes[] = 'sidebar-position-right';
        break;
        case "none":
          $classes[] = 'no-sidebar';
        break;
        default:
          $classes[] = 'sidebar-position-left';
        break;
      }
    }else{
      $classes[] = 'no-sidebar';
    }
  }else{
    // OTHER PAGES
    // add body class depending on sidebar position
    switch(osetin_get_field('sidebar_position', 'option')){
      case "left":
        $classes[] = 'sidebar-position-left';
      break;
      case "right":
        $classes[] = 'sidebar-position-right';
      break;
      case "none":
        $classes[] = 'no-sidebar';
      break;
      default:
        $classes[] = 'sidebar-position-left';
      break;
    }
  }

完整代码为 Here

0 个答案:

没有答案