这段代码对我有用:https ://github.com/Kail0/wp-materialize-navwalker
in header.php
<nav role="navigation">
<div class="nav-wrapper container">
<a id="logo-container" href="#" class="brand-logo">Logo</a>
<a href="#" data-activates="nav-mobile" class="button-collapse"><i class="fa fa-bars" aria-hidden="true"></i></a>
<?php
wp_nav_menu( array(
'menu' => 'Primary',
'theme_location'=>'Primary',
'container' => '',
'menu_class' => 'right hide-on-med-and-down',
'walker' => new wp_materialize_navwalker()
));
?>
</div>
</nav>
这个代码用于响应
页脚.php
$(function() {
elemSwap = function() {
if ($(window).width() < 992) {
$('.nav-wrapper.container > ul').attr("id", "nav-mobile");
$('.nav-wrapper.container > ul').removeClass('right hide-on-med-and-down').addClass('side-nav');
$('.drag-target').on('click', function() {
$('.side-nav').removeAttr('style');
});
$('nav .button-collapse').click(function(event) {
$('.side-nav').css({
"transform": "translateX(0%)"
});
});
$('#menu-menu .dropdown-button.main-menu-item').dropdown({
inDuration: 300,
outDuration: 225,
constrain_width: true, // Does not change width of dropdown to that of the activator
hover: false, // Activate on hover
belowOrigin: true, // Displays dropdown below the button
alignment: 'left' // Displays dropdown with edge aligned to the left of button
});
// nested dropdown initialization
$('#menu-menu .dropdown-button.sub-menu-item').dropdown({
inDuration: 300,
outDuration: 225,
constrain_width: false, // Does not change width of dropdown to that of the activator
hover: false, // Activate on hover
gutter: ($('.dropdown-content').width() * 3) / 3.05 + 3, // Spacing from edge
belowOrigin: false, // Displays dropdown below the button
alignment: 'left' // Displays dropdown with edge aligned to the left of button
});
} else {
$('.nav-wrapper.container > ul').attr("id", "menu-menu");
$('.nav-wrapper.container > ul').removeClass('side-nav').addClass('right hide-on-med-and-down');
// main dropdown initialization
$('#menu-menu .dropdown-button.main-menu-item').dropdown({
inDuration: 300,
outDuration: 225,
constrain_width: true, // Does not change width of dropdown to that of the activator
hover: true, // Activate on hover
belowOrigin: true, // Displays dropdown below the button
alignment: 'left' // Displays dropdown with edge aligned to the left of button
});
// nested dropdown initialization
$('#menu-menu .dropdown-button.sub-menu-item').dropdown({
inDuration: 300,
outDuration: 225,
constrain_width: false, // Does not change width of dropdown to that of the activator
hover: true, // Activate on hover
gutter: ($('.dropdown-content').width() * 3) / 3.05 + 3, // Spacing from edge
belowOrigin: false, // Displays dropdown below the button
alignment: 'left' // Displays dropdown with edge aligned to the left of button
});
}
}
elemSwap();
$(window).resize(elemSwap);
});