[英]Wordpress menu: Remove list-items and apply “.current-menu-item” to anchor tag
Title says it all. 标题说明了一切。 In short, how to make
wp_nav_menu();
简而言之,如何制作
wp_nav_menu();
output this: 输出:
<nav>
<a>Menu Item</a>
<a class="current-menu-item">Menu Item</a>
<a>Menu Item</a>
<a>Menu Item</a>
<a>Menu Item</a>
</nav>
I read this http://css-tricks.com/snippets/wordpress/remove-li-elements-from-output-of-wp_nav_menu/ which removes the unordered list and list-items. 我阅读了此http://css-tricks.com/snippets/wordpress/remove-li-elements-from-output-of-wp_nav_menu/ ,其中删除了无序列表和列表项。
But removing the <li>
s also removes its useful .current-menu-item
class when you're on that particular page. 但是,删除
<li>
时,当您在该特定页面上时,也会删除其有用的.current-menu-item
类。 How to get that class to show up on the anchor tag instead? 如何使该类显示在锚标记上呢?
You can edit the output via the first parameter of the function wp_nav_menu($args);
您可以通过函数
wp_nav_menu($args);
的第一个参数编辑输出wp_nav_menu($args);
. 。
$args = array(
'theme_location' => '',
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu($args);
See http://codex.wordpress.org/Function_Reference/wp_nav_menu for full documentation. 有关完整的文档,请参见http://codex.wordpress.org/Function_Reference/wp_nav_menu 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.