【问题标题】:Wordpress Walker ClassWordPress 沃克课程
【发布时间】:2017-08-01 14:27:54
【问题描述】:

我需要这个菜单结构:

<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 类解决这个问题?

【问题讨论】:

  • 你试过什么?你能告诉我你的代码吗?

标签: php wordpress


【解决方案1】:

这是我的 Walker 课程,但它显示的不是我想要的:

 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 );



    }
}

【讨论】:

    猜你喜欢
    • 2010-10-09
    • 1970-01-01
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-11
    • 2020-04-03
    相关资源
    最近更新 更多