How to theme a menu block? I have created a custom menu (lets call it "mynav") and in my theme I've created a template specifically for it (block--menu--menu-mynav.tpl.php) which contains:

&lt;div id="mynav" class="&lt;?php print $classes; ?&gt;"&lt;?php print $attributes; ?&gt;&gt;
  &lt;?php print $content ?&gt;
&lt;/div&gt;


This works fine. 

However I'd prefer to apply the id to the unordered list that is generated and contained in $content. I guess I need to create a function MYTHEME_links__system_mynav_menu like this:

function MYTHEME_links__system_mynav_menu($variables) {
  return "TEST"; // Generate HTML here (&lt;ul id="mynav"&gt;...)
}


but it doesn't seem to have an affect.

What am I doing wrong?
In order to theme the unordered list, you need to call theme_menu_tree(). You can edit your template.php in order to call this.

function THEMENAME_menu_tree__MENUNAME($variables){
  return '&lt;ul class="your-custom-class" id="your-custom-id"&gt;' . $variables['tree'] . '&lt;/ul&gt;';
}


Then, if you want to theme your links, call theme_menu_link().

function THEMENAME_menu_link__MENUNAME($variables) {
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '&lt;li' . drupal_attributes($element['#attributes']) . '&gt;' . $output . $sub_menu . "&lt;/li&gt;\n";
}


Now, the problem with Drupal 7 is that there is a major bug when it comes to displaying the active trail of custom menus. 

See issue
Issue #520106 - No way to dynamically set active trail
Issue #942782 - Custom menus never receive an active trail

You are basically out of luck if you want some true custom menus. These issues are very long standing in the drupal community so I am not sure if they will be fixed anytime soon. I don't know if there is some PHP that can help with it. You can turn to some alternative modules in order to help ease functionaltiy, like Menu Attributes and Menu Block. They both can help get around the cruddy menu system in Drupal 7.