我有这样的菜单。单击链接后,在功能文件中设置活动菜单。不幸的是,当将我们移至单独的页面时,如果我在菜单中有两个#div1,#div2然后是divly(在其中单击活动的类),它将在两个链接上跳转,因此它起作用。如何使Wordpres将#div1和#div2视为独立的divas
功能:
<nav class="nav-collapse menu">
<?php
wp_nav_menu(
array(
'theme_location' => 'header-menu',
'walker' => new Custom_Walker_Nav_Menu_Top,
'container' => 'false'
)
);
?>
<nav>
<li><a href="strona1">Strona1</a></li>
<li class="active"><a href="#div">DIV2</a></li>
<li class="active"><a href="#div2">DIV1</a></li>
<li><a href="strona2">Strona2</a></li>
<li><a href="strona3">Strona3</a></li>
<li><a href="strona4">Strona4</a></li>
class Custom_Walker_Nav_Menu_top extends Walker_Nav_Menu
{
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$is_current_item = '';
if(array_search('current-menu-item', $item->classes) != 0)
{
$is_current_item = ' class="active"';
}
echo '<li'.$is_current_item.'><a href="'.$item->url.'">'.$item->title;
}
function end_el( &$output, $item, $depth = 0, $args = array() ) {
echo '</a></li>';
}
}