如何在wordpress的子菜单中添加类?

时间:2018-02-08 10:13:14

标签: php html css wordpress

我想在has-submenu(子项目)上添加li课程但仍然无法使用我的子菜单。

请帮帮我。

我想要菜单:I want

但我的菜单显示如下:My Menu

示例Html:Html

的header.php

<?php wp_nav_menu(array(
'theme_location'=>'primary',
'container' => 'ul',
'container_class' => 'main-menu ',
'menu_class'=>'navigation-menu', 
'link_before' => '<i class="ti-home"></i><span>', 
'link_after' => '</span>',

)); ?>

Function.php

// This theme uses wp_nav_menu() in one location.
    register_nav_menu( 'primary', __( 'Primary Menu', 'imctheme' ) );

    //add active class in menu
    add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
    function special_nav_class($classes, $item){
         if( in_array('current-menu-item', $classes) ){
                 $classes[] = 'active ';  // your new class
         }
         return $classes;
    }

2 个答案:

答案 0 :(得分:0)

您可以离散地使用wp_get_nav_menu_items()功能获取菜单项,然后根据需要输出它们。 See this link

答案 1 :(得分:0)

<强>的header.php

<div class="navbar-custom shadow">
 <div class="container">
    <div id="navigation">
       <!-- Navigation Menu-->

   <?php wp_nav_menu(array(
    'theme_location'=>'primary',
    'depth' => 3,
    'container' => 'ul',
    'container_class' => 'main-menu ',
    'menu_class'=>'navigation-menu', 
    'link_before' => '<i class="ti-home"></i><span>', 
    'link_after' => '</span>',
    'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
    'walker'=> new wp_bootstrap_navwalker()

    )); ?>
  </div>
 </div>
</div>

<强> Function.php

// Custom Navigation Walker
require_once('wp_bootstrap_navwalker.php');