Drupal trick: Returning a themed menu tree with nothing more than the system path

I remember something a long time teacher said, "Nick, if you make a suit out of a gorrilla, the arms are too long." I forgot why that was relevent to the topic of theming menu trees.

Moving on, here's a nice little function I wrote to return a themed menu tree by path.

<?php
// will return all menu items under "administration".
print theme('menu_tree_by_path','admin');

// will return links to all node submission forms
print theme('menu_tree_by_path','node/add');

// return the correct menu array by path
function menu_get_mid_by_path($path) {
// oddly, menu_get_item accepts a path, but returns the parent id.
$menu = menu_get_item(null, $path);
if (isset($menu['children'])) {
// so we have to extract the mid for theme_menu_tree from one of the child items
if ($pid = end($menu['children'])) {
$menu = menu_get_item($pid);
return $menu['pid'];
}
}
}

//theme the crap out of it
function theme_menu_tree_by_path($path) {
if ($mid = menu_get_mid_by_path($path)) {
return theme('menu_tree', $mid);
}
}

// throw a sexy party....
?>