Forum Replies Created

Viewing 1 replies (of 1 total)
  • By this do you mean you want it to automatically create wp_nav_menu’s for each top level page, so you can use them as sub menu’s for that page?

    I created a loop that goes through all the top level pages and automatically creates a sub menu in the new wp menu editor.

    I put the following in my functions.php

    <?php
    $mypages = get_pages('parent=0');
    	foreach($mypages as $page)
    	{
    $slug = $page->post_name;
    $title = $page->post_title." Sub Nav";
    register_nav_menus(array($slug => __( $title )));
    
    	}
    ?>

    and then put this in my sidebar.php (or wherever you want the sub-menus displayed).

    <?php
    
    $mypages = get_pages('parent=0');
    $count = 0;
    	foreach($mypages as $page)
    	{
    $content = $page->post_name;
    $title = $page->post_title." Sub Nav";
    
    if(is_page($content) || is_child($content)) {
    wp_nav_menu( array( 'container_class' => 'sidebar-subnav', 'theme_location' => $content ) );
    } 
    
    	}
    ?>

    I also used the is_child plugin to make use of the is_child function so that the sub menu displays on the child pages too.

    I hope this is what you meant, if not it might come in handy for others.

Viewing 1 replies (of 1 total)