wp-bootstrap-navwalker icon indicating copy to clipboard operation
wp-bootstrap-navwalker copied to clipboard

Componet Alignment

Open KasperAndersson opened this issue 12 years ago • 2 comments

Hi,

This is not a issue, more a request. Since 3.0, Bootstap supported navbar component alignment - http://getbootstrap.com/components/#navbar-component-alignment

It whould be nice, to have a feature making it possible to split the navigation up.

  • If this is already possible, I'll apologies for the post.

KasperAndersson avatar Feb 14 '14 15:02 KasperAndersson

Hey Kasper,

This is actually how I use the walker on most of my sites. There is no real way to include this in the class as it requires two separate lists of menu items. The best way is to declare two separate menus and include the alignment in your wp_nav_menu() declaration. Here is what the code may look like.


<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="<?php bloginfo('url'); ?>">
                <?php bloginfo('name'); ?>
            </a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <?php
                wp_nav_menu( array(
                    'menu'       => 'primary_left',
                    'theme_location' => 'primary_left',
                    'depth'      => 2,
                    'container'  => false,
                    'menu_class' => 'nav navbar-nav',
                    'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
                    'walker' => new wp_bootstrap_navwalker())
                );

                wp_nav_menu( array(
                    'menu'       => 'primary_right',
                    'theme_location' => 'primary_right',
                    'depth'      => 2,
                    'container'  => false,
                    'menu_class' => 'nav navbar-nav navbar-right',
                    'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
                    'walker' => new wp_bootstrap_navwalker())
                );
            ?>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

The key difference here is they we are setting the container property to false and removing the container_class property. This would typically be the properties we would set to wrap our menu in a container, but in this case we want just the list of navigation items.

In the second wp_nav_menu() the container property is also set to false, and we use the menu_class property to add the navbar-right class to right align it.

SideQuestDIY avatar Feb 14 '14 16:02 SideQuestDIY

Hi Edward,

Thanks for the answers, I was about to implement a solution close to this on my project.

KasperAndersson avatar Feb 24 '14 11:02 KasperAndersson