0

Hey Folks!

I am looking for the best WP practises to handle mega large menu. My navigation menu has about 400 links, so if I create just a single menu, then it looks so ugly... I could divide it into many sub menus but don't know how to do it in right way.

Thinking of creating the main menus and say 10 sub menus. That will look much better, but then how my php script should look like? Now I have this script :

<div class="col-md-12">
<?php
    wp_nav_menu( array(
    'theme_location'    => 'primary',
    'container'         => 'div',
    'container_class'   => 'navbar-collapse navbar-main-collapse',
    'menu_class'        => 'nav navbar-nav',
    'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
    'walker'            => new wp_bootstrap_navwalker())
    );
?>
</div>

Thanks in advance.


PS. My menu sort of this:

main menu -

 1. item-1
         - sub-1
            - subsub-1
                * subsubsub-1....10
            - subsub-2 ....
                * subsubsub-1....10
            - subsub-20
                * subsubsub-1....10
         - sub-2 ....
            - subsub-1
                * subsubsub-1....10
            - subsub-2 ....
                * subsubsub-1....10
            - subsub-20 .....
                * subsubsub-1....10
         - sub-10
            - subsub-1
                * subsubsub-1....10
            - subsub-2 ....
                * subsubsub-1....10
            - subsub-20
                * subsubsub-1....10
 2. item-2
         - sub-1
            - subsub-1
                * subsubsub-1....10
            - subsub-2 ....
                * subsubsub-1....10
            - subsub-20
                * subsubsub-1....10
         - sub-2 ....
 3. item-3
         - sub-1
            - subsub-1
                * subsubsub-1....10
            - subsub-2 ....
                * subsubsub-1....10
            - subsub-20
                * subsubsub-1....10
         - sub-2 ....
  • 1
    The first thing that comes to my mind is unless this is a huge media site (think international newspaper) you should reconsider your content structure. Not everything needs to be in a menu. Sometimes just add the parent page and have a list inside that page. Having 400 menu items really doesn't sound reasonable. But maybe you can add some more details about the use case. – kraftner Feb 25 '15 at 11:28
  • it is multi countries classifieds website – Dan Feb 25 '15 at 11:57
0

From first view this seems to be tough job, but actually even I having small skills of php could solve this problem just adding following code to my custom walker class:

if ( $depth == 1 ) { // remove this statement if depth check is not required
  if (wp_get_nav_menu_object($item->title)) {// checking if item name matches to menu name
     $item_output .= wp_nav_menu( array('menu' => $item->title, 'container_class' => 'mgmenu_tabs_panels', 'menu_class' => '', 'menu_id' => 'section'. $item->ID, 'echo' => 0 ));
   }
 }

as simple as that. This script will check if any created menu name matches sub menu item name, and when they match script will add all items from that matching menu.

Basically this script allow you divide any large menu into many smaller ones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.