Fix for add span wrapper to primary links

  1. <?php
  2. function overeasy_theme(&$existing, $type, $theme, $path) {
  3.   $hooks = genesis_theme($existing, $type, $theme, $path);
  4.   $hooks['primary_links'] = array(
  5.     'arguments' => array('links' => NULL),
  6.   );
  7.  
  8.   return $hooks;
  9. }
  10.  
  11. function phptemplate_primary_links($links, $attributes = array('class' => 'links')) {
  12.   global $language;
  13.   $output = '';
  14.  
  15.   if (count($links) > 0) {
  16.     $output = '<ul'. drupal_attributes($attributes) .'>';
  17.  
  18.     $num_links = count($links);
  19.     $i = 1;
  20.  
  21.     foreach ($links as $key => $link) {
  22.       $class = $key;
  23.  
  24.       // Add first, last and active classes to the list of links to help out themers.
  25.       if ($i == 1) {
  26.         $class .= ' first';
  27.       }
  28.       if ($i == $num_links) {
  29.         $class .= ' last';
  30.       }
  31.       if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
  32.           && (empty($link['language']) || $link['language']->language == $language->language)) {
  33.         $class .= ' active';
  34.       }
  35.       $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
  36.  
  37.       if (isset($link['href'])) {
  38.         // Pass in $link as $options, they share the same keys.
  39.         $output .= l($link['title'], $link['href'], $link);
  40.       }
  41.       else if (!empty($link['title'])) {
  42.         // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
  43.         if (empty($link['html'])) {
  44.           $link['title'] = check_plain($link['title']);
  45.         }
  46.         $span_attributes = '';
  47.         if (isset($link['attributes'])) {
  48.           $span_attributes = drupal_attributes($link['attributes']);
  49.         }
  50.         $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
  51.       }
  52.  
  53.       $i++;
  54.       $output .= "</li>\n";
  55.     }
  56.  
  57.     $output .= '</ul>';
  58.   }
  59.  
  60.   return $output;
  61. }
  62. ?>
  63.  
  64. // This is what I added on page.tpl.php
  65. <div id="primary"><?php print theme('primary_links', $primary_links, array('class' => 'links primary-links')); ?></div>

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.