I need a (D7) block print the main menu in the footer; It's not clear to me how the pieces fit together:
We implement block_info, block_view, a pre-process function and a template.
function MODULE_NAME_block_info() {
$blocks['my-footer-menu'] = array(
'info' => t('My Footer'),
);
return $blocks;
}
function MODULE_NAME_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'my-footer-menu'
$tree = menu_tree_page_data('main-menu');
$block = array( 'subject' => t('My Footer'),
'content' => theme('my-footer-menu', $tree),
);
break;
}
return $block;
}
function MODULE_NAME_theme() {
return array(
'my_footer_menu' => array(
'template' => 'my-footer-menu',
'variables' => array('tree' => NULL),
),
);
}
function template_preprocess_my_footer_menu(&$variables) {
$variables['tree'] = menu_tree_all_data('main-menu');
}
<?php
for ($i = 0; $i < count($tree); $i++) {
$menu = each($tree);
if ($menu) {
$link = array( '#theme' => 'link',
'title' => $menu[1]['link']['link_title'],
'href' => $menu[1]['link']['link_path']);
print '<a href="' . $link['href'] . '">' . $link['title'] . '</a>';
// $output = theme( 'links', $link); //this isn't right
// print $output; //returns an empty string;
}
}
?>
The above gets the top level menu items on the page, but it's not clear how to get to the children of each menu item. Sorry if it seems a bit muddled, just trying to cut my way through the weeds here.