Posted By

wza on 07/30/09


Tagged

menu textmate link links to drupal add primary span spans


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

umang_nine
dividespace
panatlantica


add spans to links drupal


 / Published in: PHP
 

  1. function theme_links($links, $attributes = array('class' => 'links')) {
  2. $output = '';
  3.  
  4. if (count($links) > 0) {
  5. $output = '<ul'. drupal_attributes($attributes) .'>';
  6.  
  7. $num_links = count($links);
  8. $i = 1;
  9.  
  10. foreach ($links as $key => $link) {
  11. $class = $key;
  12.  
  13. // Add first, last and active classes to the list of links to help out themers.
  14. if ($i == 1) {
  15. $class .= ' first';
  16. }
  17. if ($i == $num_links) {
  18. $class .= ' last';
  19. }
  20. if (isset($link['href']) && $link['href'] == $_GET['q']) {
  21. $class .= ' active';
  22. }
  23. $output .= '<li class="'. $class .'">';
  24.  
  25. if (isset($link['href'])) {
  26. // Pass in $link as $options, they share the same keys.
  27. $link['html'] = TRUE;
  28. $output .= l('<span>'. $link['title'] .'</span>', $link['href'], $link);
  29. }
  30. else if (!empty($link['title'])) {
  31. // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
  32. if (empty($link['html'])) {
  33. $link['title'] = check_plain($link['title']);
  34. }
  35. $span_attributes = '';
  36. if (isset($link['attributes'])) {
  37. $span_attributes = drupal_attributes($link['attributes']);
  38. }
  39. $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
  40. }
  41.  
  42. $i++;
  43. $output .= "</li>n";
  44. }
  45.  
  46. $output .= '</ul>';
  47. }
  48.  
  49. return $output;
  50. }

Report this snippet  

You need to login to post a comment.