主题主要链接Drupal6.x添加跨距和有用的ID

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了主题主要链接Drupal6.x添加跨距和有用的ID相关的知识,希望对你有一定的参考价值。

themes the primary links adding spans (useful for sliding doors technique) and nice ID's based on the link title rather than the standard ugly menu-851 classes etc.
  1. /**
  2.  * Adds spans and useful ID's to the primary links.
  3.  *
  4.  */
  5. function THEMENAME_links($links, $attributes = array('class' => 'links')) {
  6. $output = '';
  7.  
  8. if (count($links) > 0) {
  9. $output = '<ul'. drupal_attributes($attributes) .'>';
  10.  
  11. $num_links = count($links);
  12. $i = 1;
  13.  
  14. foreach ($links as $key => $link) {
  15.  
  16. $class = '';
  17. $needle = array('&', ' ');
  18. $replace = array('and', '-');
  19. $id = strtolower(str_replace($needle, $replace, $link['title']));
  20.  
  21. // Add first, last and active classes to the list of links to help out themers.
  22. if ($i == 1) {
  23. $class .= ' first';
  24. }
  25. if ($i == $num_links) {
  26. $class .= ' last';
  27. }
  28. if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
  29. $class .= ' active';
  30. }
  31. $output .= '<li id="'. $id .'"';
  32.  
  33. if ($class) {
  34. $output .= ' class="'. $class .'"';
  35. }
  36.  
  37. $output .= '>';
  38.  
  39. if (isset($link['href'])) {
  40. // Pass in $link as $options, they share the same keys.
  41. $link['title'] = '<span>'.$link['title'].'</span>';
  42. $link['html'] = TRUE;
  43. $output .= l($link['title'], $link['href'], $link);
  44. }
  45. else if (!empty($link['title'])) {
  46. // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
  47. if (empty($link['html'])) {
  48. $link['title'] = check_plain($link['title']);
  49. }
  50. $span_attributes = '';
  51. if (isset($link['attributes'])) {
  52. $span_attributes = drupal_attributes($link['attributes']);
  53. }
  54. $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
  55. }
  56.  
  57. $i++;
  58. $output .= "</li> ";
  59. }
  60.  
  61. $output .= '</ul>';
  62. }
  63.  
  64. return $output;
  65. }

以上是关于主题主要链接Drupal6.x添加跨距和有用的ID的主要内容,如果未能解决你的问题,请参考以下文章

Web挖掘

Drupal6.x在数据库中查找PHP代码

字符串最大跨距

图像跨距的概念

AC日记——字符串最大跨距 openjudge 1.7 26

Wordpress:将自定义 ID 添加到 wp_nav_menu 中的最终 li