简体   繁体   English

Wordpress菜单+ Bootstrap NavBar

[英]Wordpress Menu + Bootstrap NavBar

I'm now stuck with this problem below, and I hope you can help me out. 我现在在下面遇到这个问题,我希望你能帮助我。 I would really appreciate it. 我真的很感激。

1st -- I created the Wordpress Menu (got it all worked). 1 - 我创建了Wordpress菜单(完成所有工作)。 2nd -- I implemented the Bootstrap classes (eg nav navbar-nav, dropdown, dropdown-menu etc..) on the html tags of the Wordpress Menu. 第二 - 我在Wordpress菜单的html标签上实现了Bootstrap类(例如nav navbar-nav,下拉菜单,下拉菜单等)。 (got it and made it work somehow) 3rd -- To make the dropdowns work I used (preg_place) to replace the default (submenu) to (dropdown-menu) then to make the function work I used the (preg-replace) again to INSERT a class and data-toggle to the Anchor Links. (得到它并让它以某种方式工作)第3 - 为了使下拉列表工作我使用(preg_place)将默认(子菜单)替换为(下拉菜单)然后使功能工作我再次使用(preg-replace)将类和数据切换插入到锚点链接。

Now the problem is, the anchor links doesn't seem to function right at all. 现在问题是,锚链接似乎根本不起作用。

check it out here. 看看这里。 (use the navs on top) (使用顶部的导航)

HEres the code on the function.php 下面是function.php上的代码

function new_submenu_class($menu) {
$menu = preg_replace('/ class="sub-menu"/','/ class="dropdown-menu" /',$menu);  
return $menu;  
}
add_filter('wp_nav_menu','new_submenu_class');

function add_menuclass($ulclass) {
$ulclass = preg_replace('/<a/', '<a class="dropdown-toggle" data-toggle="dropdown" role="button"', $ulclass);
return $ulclass;
}
add_filter('wp_nav_menu','add_menuclass');

Thanks much guys! 非常感谢!

And btw.. i used a jQuery for the 3rd level submenu. 顺便说一下..我在第3级子菜单中使用了jQuery。 which is: 这是:

<script type="text/javascript">
$(document).ready(function() {
$('.navbar a.dropdown-toggle').on('click', function(e) {
var $el = $(this);
var $parent = $(this).offsetParent(".dropdown-menu");
$(this).parent("li").toggleClass('open');
if(!$parent.parent().hasClass('nav')) {
$el.next().css({"top": $el[0].offsetTop, "left": $parent.outerWidth() - 4});
    }

    $('.nav li.open').not($(this).parents("li")).removeClass("open");

    return false;
});
});

</script>

In the function, I would try to change this line: 在函数中,我会尝试更改此行:

$('.navbar a.dropdown-toggle').on('click', function(e) {

For this one: 对于这个:

$('.navbar').on('click', 'a.dropdown-toggle', function(e) {

Since a.dropdown-toggle has been happended... 由于a.dropdown-toggle已经发生了......
Maybe it was not present on "document ready", so the " delagation " syntax could help. 也许它没有出现在“文件就绪”上,因此“ 爆燃 ”语法可能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM