Add a div and change the classes or navigation menu using wordpress walker?

I want to know how to make a WordPress wp_nav_menu() or wp_list_pages() Walker class that will generate nav menu output like this?

<!-- Level1 -->
    <li class="current">
            <a href="#">Name</a>
<!--Level2-->
            <div class="nav-sub">
                    <ul>
                            <li><a href="#">Name</a></li>
                            <li>
                                    <a href="#">Name</a>
<!--Level3-->
                                    <div class="nav-sub">
                                            <ul>
                                                    <li>
                                                            <a href="#">Name</a>
<!--Can Add Unlimited levels If Possible-->
                                                    </li>
                                                    <li><a href="#">Name</a>
                                            </li>
                                            </ul>
                                    </div>
                            </li>
                            <li><a href="#">Name</a></li>
                            <li><a href="#">Name</a></li>
                    </ul>
            </div>
    </li>

    <!-- This is One Level only -->
    <li>
            <a href="#">Name</a>
    </li>

I tried many ways but can’t just figure it out.
Here is the current output using wp_list_pages()

Read More
<ul class="myclass">
<li id="home"><a href="/index.php">Home</a></li>
<li class="page_item page-item-2 page_item_has_children"><a href="http://localhost/wordpress/sample-page/">Sample Page</a>
<ul class="children">
<li class="page_item page-item-9"><a href="http://localhost/wordpress/sample-page/home/">Home</a></li>
</ul>
</li>
<li class="page_item page-item-19"><a href="http://localhost/wordpress/page-no-sub/">page no sub</a></li>
</ul>

Thanks in advance!

P.S: I have already read this article here http://codex.wordpress.org/Function_Reference/wp_nav_menu But can’t figure out 🙁

Related posts

Leave a Reply

1 comment

  1. Edit :

    Well, look the differents parameters and call your menu

    <?php
    class Child_Wrap extends Walker_Nav_Menu
    {
        function start_lvl(&$output, $depth)
        {
            $indent = str_repeat("t", $depth);
            $output .= "n$indent<div class="div-sub"><ul class="sub-menu">n";
        }
        function end_lvl(&$output, $depth)
        {
            $indent = str_repeat("t", $depth);
            $output .= "$indent</ul></div>n";
        }
    }
    
    wp_nav_menu( 
    
    
        array( 
            'menu' => 'navigation',//(i created this menu on the backend of wordpress)
            'container'       => 'div',
            'container_class' => 'menu-sidebar', 
            'menu_class'      => 'menu-class',
            'menu_id'         => 'menu-id',
            'theme_location' => 'primary', 
            'walker' => new Child_Wrap() 
    
        ) 
    
    
    
     ); ?>
    

    You can specified many parameters (id menu, class and id container etc…)

    source class walker

    Should you find your happiness here

    Name menu screen (‘menu’ => ‘navigation’)