Bootstrap,WordPress和NavWalker - *导航链接不工作
问题描述:
我知道这个问题已在其他帖子中解决,但是,我遇到了顶部导航链接不工作this site。Bootstrap,WordPress和NavWalker - *导航链接不工作
这是一个基于BootStrap 3并使用NavWalker将WordPress导航集成到Bootstrap结构中的WordPress网站。这里是导航代码:
<div class="navbar navbar-default col-md-9" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<?php
wp_nav_menu(array(
'menu' => 'Primary',
'theme_location' => 'Primary',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse col-md-9',
'container_id' => 'none',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
);
?>
</div><!-- /.container -->
</div><!-- /.navbar -->
这本质上缺乏悬停功能,很好的下拉菜单。我有以下解决方案从wpeden解决了这个:
(function($) {
jQuery(function($) {
$('.navbar .dropdown').hover(function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(250).slideDown();
}, function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(100).slideUp();
});
$('.navbar .dropdown > a').click(function(){
location.href = this.href;
});
});
})(jQuery);
这确实摆好显示下拉导航一个很不错的工作,但也有对父菜单项没有主动联系。
我已确认父母实际上已将其移出导航层次结构,并且没有孩子,因此显示的链接正确,因此有些东西缺失,我无法识别,并且会感激敏锐的眼睛或两个来帮助发现它。
答
NavWalker似乎是这样设计的。您需要编辑的源代码wp_bootstrap_navwalker.php在线#85。
让家长保持href
即使有孩子
if ($args->has_children && $depth === 0) {
// $atts['href'] = '#'; // old line
$atts['href'] = ! empty($item->url) ? $item->url : ''; // new line
$atts['data-toggle'] = 'dropdown';
$atts['class'] = 'dropdown-toggle';
$atts['aria-haspopup'] = 'true';
} else {
$atts['href'] = ! empty($item->url) ? $item->url : '';
}
你说的活动链接是什么意思?我发现菜单直接加载了'href =“#”' – Spokey 2014-10-28 15:16:46
嗨Spokey,这就是问题所在。有些东西正在剥离链接,我留下了#链接。如上所述,如果我将导航元素移动到没有孩子的位置,如联系人,则链接显示正确。但只要有孩子,链接就会被删除。 – fmz 2014-10-28 15:23:15