首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress Walker类

Wordpress Walker类
EN

Stack Overflow用户
提问于 2017-07-31 18:50:35
回答 1查看 50关注 0票数 0

我需要这个菜单结构:

代码语言:javascript
复制
<div>
   <nav>
      <div><a>Home</a></div>
      <div>
         <a>About Us</a>
         <div>
            <ul>
               <li><a><span class="greyArrow"></span> <span>The Company</span></a></li>
               <li><a><span class="greyArrow"></span> <span>Mission</span></a></li>
            </ul>
         </div>
      </div>
      <div>
         <a>Profiles</a>
         <div>
            <ul>
               <li><a><span class="greyArrow"></span> <span>A</span></a></li>
               <li><a <span class="greyArrow"></span> <span>B</span></a></li>
            </ul>
         </div>
      </div>
      <div><a>Employees</a></div>
   </nav>
</div>

我不能改变我的css。在我读过的walker类中,这是可能的。我如何用walker类解决这个问题呢?

EN

回答 1

Stack Overflow用户

发布于 2017-08-01 14:27:54

这是我的Walker类,但它没有显示我想要的:

代码语言:javascript
复制
 class Description_Walker extends Walker_Nav_Menu
{


    function start_lvl( &$output, $depth=0 , $args = array() ) {


        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent<div class='mainMenuPopUp' style='display: none;'><ul class='mainMenuItemChilds'>\n";



    }

    function end_lvl( &$output, $depth=0 , $args = array() ) {


        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent</ul></div>\n";


    }



    function start_el(&$output, $item, $depth, $args)
    {


        $classes = empty($item->classes) ? array () : (array) $item->classes;

        $class_names = join(' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );

        !empty ( $class_names ) and $class_names = ' class="'. esc_attr( $class_names ) . '"';


        if($depth == 0){
            $output .= "<div class='mainMenuItem'>";
        }else if($depth==1){
            $output .= "<li>";
        }



        $attributes  = '';
        !empty( $item->attr_title ) and $attributes .= ' title="'  . esc_attr( $item->attr_title ) .'"';
        !empty( $item->target ) and $attributes .= ' target="' . esc_attr( $item->target     ) .'"';
        !empty( $item->xfn ) and $attributes .= ' rel="'    . esc_attr( $item->xfn        ) .'"';
        !empty( $item->url ) and $attributes .= ' href="'   . esc_attr( $item->url        ) .'"';
        $title = apply_filters( 'the_title', $item->title, $item->ID );

        if($depth==0){
        $item_output = $args->before
        . "<a $attributes class='mainMenuItemTitle '>"
        . $args->link_before
        . $title
        . '</a></div>'
        . $args->link_after
        . $args->after;
        }else if($depth==1){
        $item_output = $args->before
        . "<a $attributes class='mainMenuItemTitle '><span class='greyArrow'></span><span class='menuChildTitle'>"
        . $args->link_before
        . $title
        . '</span></a></li>'
        . $args->link_after
        . $args->after;

        }



        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );



    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45413863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档