Aller au contenu principal
loading

Items d'un menu Drupal avec classe CSS unique pour chaque

POSTÉ DANS Drupal 6 TAGS CSS AUTEUR herve COMMENTAIRES 1

Ajouter une classe CSS sur chaque lien d'un menu Drupal

function helpdrupal_id_safe($string) {
  // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
  $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
  // If the first character is not a-z, add 'n' in front.
  if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
    $string = 'id'. $string;
  }
  return $string;
}

// menu items with unique classes for each menu item
function helpdrupal_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
    $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
    if (!empty($extra_class)) {
        $class .= ' '. $extra_class;
    }
    if ($in_active_trail) {
        $class .= ' active-trail';
    }
    #New line added to get unique classes for each menu item
    $css_class = helpdrupal_id_safe(str_replace(' ', '_', strip_tags($link)));
    return '<li class="'. $class . ' ' . $css_class . '">' . $link . $menu ."</li>\n";
}



1 commentaire