Search code examples
cssdrupal-theming

drupal menu customizacion via css?


I've been fiddling around with drupal theming quite succesfully (or at least, that's what i think), but when I tried to inject css coding to the primary links menu to customize it as i generally do via html+css, i hit a wall.

I have been able to apply css styles to divs, links and text, but I would like to customize the primary (and secondary) links menus much more, perhaps with some css sprite menu techniques, but while remaining drupal-compliant and using as much of drupal's own php in the process. or if i really have to rewrite some code, i don't mind, though i am not quite the programmer yet.

i have been around several sites but i haven't anything particularly useful, so if anyone can point me to the right direction, i will be quite grateful.

thanx in advance.


Solution

  • You can add a id-like class for each menu item - add this function in your template.php

    function mythemename_menu_item_link($link) {
      if (empty($link['localized_options'])) {
        $link['localized_options'] = array();
      }
    
      // LOOK HERE
      // add a key for main menu items, so we can theme each item in a different way
      // add this class only for a specific menu
      if ($link['menu_name'] == 'menu-menu-mymenu') {
        if ($link['localized_options']['attributes']['class']) {
          $link['localized_options']['attributes']['class'] .= ' menu-'. $link['mlid'];
        }
        else {
          $link['localized_options']['attributes']['class'] = 'menu-'. $link['mlid'];
        }
      }
    
      return l($link['title'], $link['href'], $link['localized_options']);
    }
    

    This code can be cleaner, but i've added more lines so you can read it better.