0

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.

0

You can create all of the code yourself, but you could also use the menu block module instead and save yourself a lot of work.

1
  • $menu = menu_navigation_links('main-menu'); print drupal_render(menu_tree_output(menu_tree_all_data('main-menu'))); – August1914 Nov 12 '12 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.