Domanda

Sto cercando di aggiungere menù a scomparsa per un tema Drupal, che utilizza il testo scorrevole arrotondamento porta CSS.

La versione corrente usa un link primario iniezione della campata nei tag A, che funziona bene. Ma non supporta menu a discesa.

Codice di funzionamento:

<?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?>

Nel modello con un file template.php aggiunta:

<?php
// function for injecting spans inside anchors which we need for the theme's rounded corner background images
function strands_guybrush_links($links, $attributes =  array('class' => 'links')) {
  $output = '';
  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
      $class = $key;

      // Add first, last and active classes to the list of links to help out themers.
      if ($i == 1) {
        $class .= ' first';
      }
      if ($i == $num_links) {
        $class .= ' last';
      }
      if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
        $class .= ' active';
      }
      $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';

      if (isset($link['href'])) {
        $link['title'] = '<span class="link">' . check_plain($link['title']) . '</span>';
        $link['html'] = TRUE;      
        // Pass in $link as $options, they share the same keys.
        $output .= l($link['title'], $link['href'], $link);        
      }
      else if (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (empty($link['html'])) {
          $link['title'] = check_plain($link['title']);
        }
        $span_attributes = '';
        if (isset($link['attributes'])) {
          $span_attributes = drupal_attributes($link['attributes']);
        }
        $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</li>\n";
    }

    $output .= '</ul>';
  }
  return $output;
}
?>

Così ho aggiunto il Nizza modulo menu che funziona bene e permette la discesa per le funzioni del menu la mia navigazione che ora è indirizzata dal modello utilizzando:

<?php   print theme_nice_menu_primary_links() ?>

Il problema è che i tag la necessità di avere campate all'interno per consentire la marcatura stato selezionato. Ho provato ogni angolo ho potuto trovare per modificare il menu_item_link funzione di Drupal che viene utilizzato da belle menu per creare i link.

es. Ho guardato il forum di Drupal per due giorni e nessuna gioia.

Le linee del modulo che costruiscono i collegamenti sono:

function theme_nice_menu_build($menu) {
  $output = '';
  // Find the active trail and pull out the menus ids.

  menu_set_active_menu_name('primary-links');
  $trail = menu_get_active_trail('primary-links');
  foreach ($trail as $item) {
    $trail_ids[] = $item['mlid'];
  }

  foreach ($menu as $menu_item) {
    $mlid = $menu_item['link']['mlid'];
    // Check to see if it is a visible menu item.
    if ($menu_item['link']['hidden'] == 0) {
      // Build class name based on menu path
      // e.g. to give each menu item individual style.
      // Strip funny symbols.
      $clean_path = str_replace(array('http://', '<', '>', '&', '=', '?', ':'), '', $menu_item['link']['href']);
      // Convert slashes to dashes.
      $clean_path = str_replace('/', '-', $clean_path);
      $class = 'menu-path-'. $clean_path;
      $class .= in_array($mlid, $trail_ids) ? ' active' : '';  
      // If it has children build a nice little tree under it.
      if ((!empty($menu_item['link']['has_children'])) && (!empty($menu_item['below']))) {
        // Keep passing children into the function 'til we get them all.
        $children = theme('nice_menu_build', $menu_item['below']);
        // Set the class to parent only of children are displayed.
        $class .= $children ? ' menuparent ' : '';
        // Add an expanded class for items in the menu trail.
        $output .= '<li id="menu-'. $mlid .'" class="'. $class .'">'. theme('menu_item_link', $menu_item['link']);
        // Build the child UL only if children are displayed for the user.
        if ($children) {
          $output .= '<ul>';
          $output .= $children;
          $output .= "</ul>\n";
        }  
        $output .= "</li>\n";
      }  
      else {
        $output .= '<li id="menu-'. $mlid .'" class="'. $class .'">'. theme('menu_item_link', $menu_item['link']) .'</li>'."\n";
      }  
    }  
  }
  return $output;
}

Come si può vedere l'uscita $ menu_item_link utilizza per analizzare l'array in legami e ha aggiunto la classe di attivo al collegamento di navigazione selezionato.

La domanda è: come faccio ad aggiungere un arco all'interno dei tag A o come faccio avvolgere il tag a, con un arco che ha la classe di attivi per lo stile dei collegamenti porte scorrevoli?

È stato utile?

Soluzione

Se si desidera avvolgere i tag una con un arco, è possibile sovrascrivere il theme_nice_menu_build e aggiungere la durata della all'uscita. Se si vuole all'interno del tag è necessario sovrascrivere il menu_item_link.

È possibile sovrascrivere un funciton tema di creazione di una your_theme_name_function_name funzione di chiamata e Drupal utilizzerà questa funzione per rendere il markup al posto di quello di default. In questo modo è possibile modificare il markup qualsiasi modo si desidera. Questa funzione dovrebbe essere nel file di template.php del vostro tema.

Un buon modo per iniziare è quello di copiare la funzione che si desidera sovrascrivere e modificare solo secondo le tue preferenze.

Molto è accaduto da Drupal 4.7, non mi auguro si utilizza questo. E 'abbastanza facile da inserire tag span:

function your_theme_name_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
  $link['localized_options']['html'] = TRUE;
  return l('<span>' . $link['title'] . '</span>', $link['href'], $link['localized_options']);
}

Ho provato questo e funziona bene.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top