Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bootstrap 3 Megamenu for WordPress with multi level dropdowns.

NotificationsYou must be signed in to change notification settings

jaycbrf4/wp_boostrap-navwalker-mega

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

A custom WordPress nav walker class to fully implement the Bootstrap 3.0+ navigation style with Mega Menu items in a custom theme using the WordPress built in menu manager.

http://prntscr.com/h7206f <- screenshot of menu

http://prntscr.com/h720sy < - screenshot of widgets screen

http://prntscr.com/h721hh <- screenshot of menu screen

This version adds the support for multi level dropdowns with Mega Menu type nav items

NOTE

This is a utility class that is intended to format your WordPress theme menu with the correct syntax and classes to utilize the Bootstrap dropdown navigation, and does not include the required Bootstrap JS files. You will have to include them manually.

Installation

Placewp_bootstrap-mega-navwalker.php in your WordPress theme folder/wp-content/your-theme/

Open your WordPress themesfunctions.php file/wp-content/your-theme/functions.php and add the following code:

// Register Custom Navigation Walkerrequire_once('wp_bootstrap-mega-navwalker.php');

Usage

Update yourwp_nav_menu() function inheader.php to use the new walker by adding a "walker" item to the wp_nav_menu array.

<?php$args =array('theme_location' =>'mega_menu','depth' =>0,'menu_class'  =>'nav navbar-nav','walker'  =>newBootstrapNavMenuWalker()          );wp_nav_menu($args);?>

Your menu will now be formatted with the correct syntax and classes to implement Bootstrap dropdown navigation.

You will also want to declare your new menu in yourfunctions.php file.

register_nav_menus( array('mega_menu'   => __( 'Mega Menu', 'your-theme' ),) );

Now you will need to add the Widget that will contain the mega-menu item's HTML. In your functions file add this code to the register sidebars function:

//register MegaMenu widget if the Mega Menu is set as the menu location$location = 'mega_menu';$css_class = 'mega-menu-parent';$locations = get_nav_menu_locations();if ( isset( $locations[ $location ] ) ) {  $menu = get_term( $locations[ $location ], 'nav_menu' );  if ( $items = wp_get_nav_menu_items( $menu->name ) ) {    foreach ( $items as $item ) {      if ( in_array( $css_class, $item->classes ) ) {        register_sidebar( array(          'id'   => 'mega-menu-item-' . $item->ID,          'description' => 'Mega Menu items',          'name' => $item->title . ' - Mega Menu',          'before_widget' => '<li>',          'after_widget' => '</li>',         ));      }    }  }}

Typically the menu is wrapped with additional markup, here is an example of a navbar-fixed-top menu that collapse for responsive navigation.

<nav>  <div><div>       <button type="button" data-toggle="collapse" data-target="#bootstrap-nav-collapse"><span>Toggle navigation</span><span></span><span></span><span></span></button> <a href="<?php echo site_url(); ?>"><img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt=""/></a></div><!-- /. navbar-header -->    <!-- Collect the nav links from WordPress -->  <div>           <?php $args = array(  'theme_location' => 'mega_menu',  'depth' => 0,  'menu_class'  => 'nav navbar-nav',  'walker'  => new BootstrapNavMenuWalker()  );    wp_nav_menu($args);  ?>  </div><!-- ./collapse -->  </div><!-- /.container --></nav>

Displaying the Menu

To display the menu you must associate your menu with your theme location. You can do this by selecting your theme location in theTheme Locations list wile editing a menu in the WordPress menu manager and selecting mega-menu.

Displaying the Mega Menu

To display the mega menu items add the class "mega-menu-parent" to the menu item in the WordPress menu manager. This will create a new widget in the widgets section with the same name as the nav parent. Add a Custom HTML widget and code your mega menu items using default bootstrap containers, rows and cols. Add a search widget or any other widget, style the CSS by the item's ID.

Additional CSS to get the menu to display correctly:

/**Mega Menu **/.navbar .container {    position: relative;}.navbar-nav, .navbar .collapse, .navbar-nav li {  position: static;}.menu-item-has-children, .menu-item-has-children .dropdown-menu {  left: auto;}.menu-item-has-children .dropdown-menu {  width: auto !important;}

And optional css for a hover/fade inUp effect

@media (min-width: 767px) {/** make dropdown active on hover and fade in - change to 992px for alt breakpoint and swap bootstrap.css files **/  ul.nav li.dropdown > ul.dropdown-menu{    visibility:hidden;    display:block;    opacity:0;    margin-top: 10px !important;    transition: all  0.5s ease-in-out;  }  ul.nav li.dropdown:hover > ul.dropdown-menu{    visibility:visible;    opacity: 1;    display: block;    margin-top: 0 !important;     border-bottom-right-radius: 16px;    border-bottom-left-radius: 16px;  }

Based on WPBootstrapNavwalker by by johnmegahanhttps://gist.github.com/1597994, Emanuele 'Tex' Tessorehttps://gist.github.com/3765640

About

Bootstrap 3 Megamenu for WordPress with multi level dropdowns.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp