最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

menus - Need help with Walker_Nav_Menu class

programmeradmin4浏览0评论

I am trying to learn how to use walker_nav_menu for past week but can't find the right material. WP documentation just cover simple definition of walker nav menu class. And most of the resources i found are not really working or outdated.

My walker class:

class WP_Bootstrap extends Walker_Nav_Menu {

  public function start_lvl( &$output, $depth = 0, $args = array() ) {
   $indent = str_repeat("\t",$depth);
   $output .= "\n$indent<ul class=\"dropdown-menu$submenu depth_$depth\">\n"; 
 }

  public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {

 }
} 

My wp nav menu:

wp_nav_menu( array( 
            'theme_location' => 'top',
            'container' => 'div',
            'container_class' => 'collapse navbar-collapse',
            'container_id' => 'navbarNav',
            'menu_class'   => 'navbar-nav mr-auto',
            'walker' => new Wp_Bootstrap(),
        ) );

Why it's not working? i can't really see the output. I also want to change class of li.

发布评论

评论列表(0)

  1. 暂无评论