2

I am trying this code

   echo "<select>" .$main_nav = menu_tree('secondary-links');

            print"<option>"     .    $main_nav   . " </option></select>";<br>

but it display all menu at ones

1

It looks like you're building a so-called "jump menu", is that correct?

It's not considered good practice to code a menu into a template like you're doing in your example. Try to build the functionality of your site with modules (existing ones, or custom) and use the theme (template.php, CSS files, template files) for appearance only.

If you need a jump menu, have a look at the Jump module. It provides a block for every top-level menu and every vocabulary, so it could get you exactly what you need without writing one line of code.

  • About splitting the code: could you point us to some references (articles, existing themes etc.) where it's done well? I'm interested. – Scorchio Feb 7 '12 at 10:24
  • 1
    For instance, see how menu_tree_output() builds a list of menu items and then calls theme('menu_item_link', ...), theme('menu_item', ...) and theme('menu_tree', ...) to generate the html. See also Using the theme layer in the module developers guide. – marcvangend Feb 7 '12 at 12:59

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.