Display all menu levels I'm trying to output a menu with all of its submenus into a template file, currently I'm using the code below. The problem is that it only displays the top level links. If I pass the second $level parameter into menu_navigation_links it'll then only display that one level, not any of the others above or below.

How can I display all the different menu levels &amp; still have the ability to add classes to the  as below? The title isn't really that important as I can 'hard code' that tag into the template file.

print theme('links__menu_top_page_navigation', array('links' =&gt; menu_navigation_links('menu-top-page-navigation'), 'attributes' =&gt; array('id' =&gt; 'main-menu', 'class' =&gt; array('main-menu', 'list-menu')), 'heading' =&gt; array('text' =&gt; t('Main menu'),'level' =&gt; 'h2','class' =&gt; array('main-menu-title'))));


The closest thing I've found so far is to use menu_tree_all_data() &amp; menu_tree_all_output() but I cannot see how to edit the  class using that.
I've managed to find an answer in a Stack Overflow answer https://stackoverflow.com/a/30570027/1094862

For completeness I've copied the relevant code below:

$main_menu_tree = menu_tree_all_data('menu-name', null, 3);
render_menu_tree($main_menu_tree);

function render_menu_tree($menu_tree) {
  print '&lt;ul&gt;';
  foreach ($menu_tree as $link) {
    print '&lt;li&gt;';
    $link_path = '#';
    $link_title = $link['link']['link_title'];
    if($link['link']['link_path']) {
        $link_path = drupal_get_path_alias($link['link']['link_path']);
    }
    print '&lt;a href="' . $link_path . '"&gt;' . $link_title . '&lt;/a&gt;';
    if(count($link['below']) &gt; 0) {
      render_menu_tree($link['below']);
    }
    print '&lt;/li&gt;';
  }
  print '&lt;/ul&gt;';
}