array instead of object
I've successful used wp bootstrap navwalker in a theme, but when i've exported my code on other theme is nothing is working.
here's my code :
<div id="bs-example-navbar-collapse-1" class="collapse navbar-collapse">
<?php
wp_nav_menu(array(
'theme_location' => 'main',
'menu_class' => 'nav navbar-nav',
'menu' => 'main-menu',
'depth' => 2,
'walker' => new wp_bootstrap_navwalker()
));
?>
<?php echo '<ul class="nav navbar-nav navbar-right"><li>'. get_search_form(false).'</li></ul>'; ?>
</div><!-- /.navbar-collapse -->
the result is a empty list with no title and no depth either. my primary menu works in the non bootstrap default wordpress theme.
i saw on your class some "is_object($args[0])", but on my wordpress $args[0] is an array, and $id_field is 'DB_ID', so maybe i miss a server prerequisite ?
thanks,
i've also tried :
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
but it fails stronger with this callback (no menu items)
If no menu is assigned to the location in the WordPress admin nothing will show. As of WordPress 3.7 you must manually assign the menu to the theme location for it to show up.
If you include the custom fallback 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', you will see a menu item with an "Add Menu" link that links you to the menu admin so you can select a menu. This link will only show up is you are logged in as an admin that can edit the menu.
i do have items, but they are empty https://www.dropbox.com/s/w7iy6j3eihxmofk/Capture%20d%27%C3%A9cran%202014-03-03%2022.56.01.png https://www.dropbox.com/s/4ypattjgisz9z8k/Capture%20d%27%C3%A9cran%202014-03-03%2022.54.23.png
Very interesting. This is exactly what happens in WordPress 3.7+ when the custom fallback of 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', is not defined and a menu is not set the to location. This happens because when the custom fallback is not defined WordPress defaults to using wp_page_menu() as a fallback. The results returned form wp_page_menu() cannot be processed by the walker and will be broken every time so the 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', is required if you are working with WordPress 3.7+
Since your menu is defined in the admin, the only conclusion I can come to is that there is a typo in the theme location name between your wp_nav_menu() function in header.php and your register_nav_menus() function in functions.php
To troubleshoot further I would need to see a copy of your header.php and functions.php files.
here are the current files : header.php : https://gist.github.com/fxguillois/9389549 functions.php : https://gist.github.com/fxguillois/9389580 primary-menu.php : https://gist.github.com/fxguillois/9389620
thanks,
Thank you for providing the files. After taking a look at the code I issue is exactly as I mentioned above, the name of the menu in your primary-menu.php and functions.php do not match.
In your functions.php file you find the following code.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'archipels' ),
) );
This is what defines the menu in your WordPress admin and is the defined menu you are assigning a menu to in the admin. For you to assign a menu to your wp_nav_menu() location in primary-menu.php, the chosen menu name and the menu name use in your register_nav_menus() declaration in functions.php must match.
Since your menu in primary-menu.php is named menu your register_nav_menus() declaration in functions.php would have to read:
register_nav_menus( array(
'main' => __( 'Main Menu', 'archipels' ),
) );
The menu is also as previously mentioned simply displaying the sites pages using wp_page_menu() as a fallback which does not support custom walkers. When using the custom walker the 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', fallback function must be defined or the result will be exactly as your screenshots above show.
Your wp_nav_menu() should read:
wp_nav_menu(array(
'theme_location' => 'main',
'menu_class' => 'nav navbar-nav',
'menu' => 'main-menu',
'depth' => 2,
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
));
thanks, sorry for bothering and time lost. :s
Not a problem. I find a lot of the time all it takes is a second pair of eyes to look at the problem.