【问题标题】:Wordpress Responsive Select MenuWordpress 响应式选择菜单
【发布时间】:2012-10-11 03:05:52
【问题描述】:

我在 WordPress 中创建了一个响应式网站。该网站有许多不同的导航区域,当通过移动设备查看网站时,我希望将它们合并到一个选择菜单中。

我的 WordPress header.php 文件中的代码目前如下所示:

<?php dropdown_menu( array('dropdown_title' => '-- Main Menu --', 'container' => 'div',  'theme_location'=>'main_menu') ); ?>

但是,我想在这个选择下拉列表中合并多个菜单并尝试过:

<?php dropdown_menu( array('dropdown_title' => '-- Main Menu --', 'container' => 'div',  'theme_location'=>'main_menu', 'theme_location'=>'top_menu', 'theme_location'=>'footer_menu') ); ?>

不幸的是,这仍然只显示最后一个菜单“footer_menu”,而不是结合所有三个菜单。关于如何正确编辑上述代码以便所有菜单在选择框中显示为一个的任何想法?

任何帮助将不胜感激。

【问题讨论】:

    标签: php arrays wordpress responsive-design


    【解决方案1】:

    您可以使用我在某些项目中经常使用的代码,一些简单的可以自定义 jQuery 的代码

    你可以改变值来设置一个特定的div

    var $mainNav    = $('#menu').children('ul'),
    

    代码完整的jQuery

    (function($) {
        var $mainNav    = $('#menu').children('ul'),
            optionsList = '<option value="" selected>Navigate...</option>';
    
        // Regular nav
        $mainNav.on('mouseenter', 'li', function() {
            var $this    = $(this),
                $subMenu = $this.children('ul');
            if( $subMenu.length ) $this.addClass('hover');
            $subMenu.hide().stop(true, true).fadeIn(200);
        }).on('mouseleave', 'li', function() {
            $(this).removeClass('hover').children('ul').stop(true, true).fadeOut(50);
        });
        // Responsive nav
        $mainNav.find('li').each(function() {
            var $this   = $(this),
                $anchor = $this.children('a'),
                depth   = $this.parents('ul').length - 1,
                indent  = '';
            if( depth ) {
                while( depth > 0 ) {
                    indent += '--';
                    depth--;
                }
            }
            optionsList += '<option value="' + $anchor.attr('href') + '">' + indent + ' ' + $anchor.text() + '</option>';
        }).end().after('<select class="responsive-nav">' + optionsList + '</select>');
        $('.responsive-nav').on('change', function() {
            window.location = $(this).val();
        });
    })(jQuery);
    

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      • 2016-01-09
      • 1970-01-01
      • 1970-01-01
      • 2015-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多