2014-12-26 3 views
0

"하위 메뉴"를 변경하는 방법이 많이 발견되었지만 문제는 내 친구가 새로운 Walker_Nav_Menu로 코드화되어 있으며 여기에 코드가 있습니다. wp_nav_menu 하위 메뉴 & li> 클래스 이름을 변경하고 추가 하시겠습니까?

내가 원하는 건

은 다음과 같습니다 CLASS="ADD New HERE"
  • 는 4 라인의 클래스를 변경하는 경우

    1. 다시 5에 클래스를 추가 <ul class="sub-menu">에서 <ul class="dropdown">
    2. 에, 3 라인에서 클래스를 추가 할 수 3 번째 라인과 같습니다. 설명을

      <ul id="menu-herid" class="nav navbar-nav" data-breakpoint="800"> 
      <li id="menu-item-2821" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children"> 
          <a CLASS="ADD New HERE" href="http://theme.dev/home/">Home</a> 
           <ul class="sub-menu"> 
           <li id="menu-item-2838" class="menu-item menu-item-type-post_type menu-item-object-page"> 
            <a href="http://theme.dev/blog-with-slideshow/">Blog with Slideshow</a> 
            </li> 
           </ul> 
      </li> 
      </ul> 
      

      // 탐색

      if (! class_exists('hs_description_walker')) { 
           class hs_description_walker extends Walker_Nav_Menu { 
            function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { 
             global $wp_query; 
             $indent = ($depth) ? str_repeat("\t", $depth) : ''; 
      
             $class_names = $value = 'class="dropdown"'; 
      
             $classes = empty($item->classes) ? array() : (array) $item->classes; 
      
             $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item)); 
             $class_names = ' class="'. esc_attr($class_names) . '"'; 
      
             $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>'; 
      
             $attributes = ! empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) .'"' : ''; 
             $attributes .= ! empty($item->target)  ? ' target="' . esc_attr($item->target ) .'"' : ''; 
             $attributes .= ! empty($item->xfn)  ? ' rel="' . esc_attr($item->xfn  ) .'"' : ''; 
             $attributes .= ! empty($item->url)  ? ' href="' . esc_attr($item->url  ) .'"' : ''; 
      
             $description = ! empty($item->description) ? '<span class="desc">'.esc_attr($item->description).'</span>' : ''; 
      
             if($depth != 0) { 
              $description = $append = $prepend = ""; 
             } 
      
             $item_output = $args->before; 
             $item_output .= '<a'. $attributes .'>'; 
             $item_output .= $args->link_before; 
      
             if (isset($prepend)) 
              $item_output .= $prepend; 
      
             $item_output .= apply_filters('the_title', $item->title, $item->ID); 
      
             if (isset($append)) 
              $item_output .= $append; 
      
             $item_output .= $description.$args->link_after; 
             $item_output .= '</a>'; 
             $item_output .= $args->after; 
      
             $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); 
            } 
           } 
          } 
      

    이제 일이 내가 하위 메뉴가

  • 답변

    1
    $defaults = array(
        'theme_location' => '', 
        'menu'   => 'menu-name', 
        'container'  => 'div', 
        'container_class' => '', 
        'container_id' => '', 
        'menu_class'  => 'menu', 
        'menu_id'   => '', 
        'echo'   => true, 
        'fallback_cb'  => 'wp_page_menu', 
        'before'   => '', 
        'after'   => '', 
        'link_before'  => '', 
        'link_after'  => '', 
        'items_wrap'  => '<ul id="%1$s" class="%2$s">%3$s</ul>', 
        'depth'   => 0, 
        'walker'   => new My_Walker_Nav_Menu() //call walker 
    ); 
    //Add this in your theme functions.php file 
    class My_Walker_Nav_Menu extends Walker_Nav_Menu { 
        function start_lvl(&$output, $depth) { 
        $indent = str_repeat("\t", $depth); 
        $output .= "\n$indent<ul class=\"dropdown\">\n"; 
        } 
    } 
    
    0

    가이 코드에 시도 ""로 변경하고 싶었입니다 ...

    HTML DEMO

    참조 link

    Wordress 코드

    <nav class="navbar-collapse collapse photoshoot-menu"> 
        <?php wp_nav_menu(array('theme_location' => 'primary','container' => ' ')); ?> 
    </nav>