我想在 wordpress walker 导航中为父 li 添加 class,而不是子 li
I want to add class for the parents li in wordpress walker navigation , not to sub li
下面是我想将 hvr-bounce-to-bottom 的 class 添加到父 li 的导航结构。谁能帮帮我。下面我 php 和 html 代码一切正常只有父 class 没有添加
<div id="cssmenu">
<ul>
<li class="active hvr-bounce-to-bottom"><a href="index.html">Home</a>
</li>
<li class="hvr-bounce-to-bottom"><a href="social.html">Social Media</a>
</li>
<li class="hvr-bounce-to-bottom"><a href="animation.html">Animated Videos</a>
</li>
<li class="hvr-bounce-to-bottom"><a href="webdesign.html">Web Development</a>
</li>
<li class="hvr-bounce-to-bottom dropdown"><a href="writing.html">Content Writing </a>
<ul class="dropdown">
<li><a href="#">Test one</a></li>
<li><a href="#">Test one</a></li>
<li><a href="#">Test one</a></li>
<li><a href="#">Test one</a></li>
</ul>
</li>
<li class="hvr-bounce-to-bottom"><a href="translation.html">Translation</a>
</li>
<li class="hvr-bounce-to-bottom"><a href="portfolio.html">Portfolio </a>
</li>
</ul>
</div>
<?php
wp_nav_menu( array(
'menu' => 'Main Menu',
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_id' => 'cssmenu',
'menu_class' => 'menu-li',
'items_wrap' => '<ul>%3$s</ul>',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
);
?>
您必须编辑助行器才能实现此目的。在 wp-bootstrap-navwalker.php 中搜索以下行:
$classes[] = 'menu-item-' . $item->ID;
并在其后添加这一行:
if ( $depth === 0 ) $classes[] = 'hvr-bounce-to-bottom';
这会将 hvr-bounce-to-bottom class 添加到任何非子菜单项(菜单深度为 0)的 li 元素。
下面是我想将 hvr-bounce-to-bottom 的 class 添加到父 li 的导航结构。谁能帮帮我。下面我 php 和 html 代码一切正常只有父 class 没有添加
<div id="cssmenu">
<ul>
<li class="active hvr-bounce-to-bottom"><a href="index.html">Home</a>
</li>
<li class="hvr-bounce-to-bottom"><a href="social.html">Social Media</a>
</li>
<li class="hvr-bounce-to-bottom"><a href="animation.html">Animated Videos</a>
</li>
<li class="hvr-bounce-to-bottom"><a href="webdesign.html">Web Development</a>
</li>
<li class="hvr-bounce-to-bottom dropdown"><a href="writing.html">Content Writing </a>
<ul class="dropdown">
<li><a href="#">Test one</a></li>
<li><a href="#">Test one</a></li>
<li><a href="#">Test one</a></li>
<li><a href="#">Test one</a></li>
</ul>
</li>
<li class="hvr-bounce-to-bottom"><a href="translation.html">Translation</a>
</li>
<li class="hvr-bounce-to-bottom"><a href="portfolio.html">Portfolio </a>
</li>
</ul>
</div>
<?php
wp_nav_menu( array(
'menu' => 'Main Menu',
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_id' => 'cssmenu',
'menu_class' => 'menu-li',
'items_wrap' => '<ul>%3$s</ul>',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
);
?>
您必须编辑助行器才能实现此目的。在 wp-bootstrap-navwalker.php 中搜索以下行:
$classes[] = 'menu-item-' . $item->ID;
并在其后添加这一行:
if ( $depth === 0 ) $classes[] = 'hvr-bounce-to-bottom';
这会将 hvr-bounce-to-bottom class 添加到任何非子菜单项(菜单深度为 0)的 li 元素。