문제

텍스트 슬라이딩 도어 CSS 반올림을 사용하는 드 루 팔 테마에 드롭 다운 메뉴를 추가하려고합니다.

현재 버전은 기본 링크를 A 태그로 SPAN을 사용하여 제대로 작동합니다. 그러나 드롭 다운 메뉴를 지원하지 않습니다.

작업 코드 :

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

Template.php 파일 추가 템플릿에서 :

<?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;
}
?>

그래서 나는 그것을 추가했다 좋은 메뉴 모듈 이는 잘 작동하고 내비게이션에 대한 드롭 다운 메뉴 기능을 사용하여 다음을 사용하여 템플릿에서 해결됩니다.

<?php   print theme_nice_menu_primary_links() ?>

문제는 A 태그가 선택한 상태 마크 업을 허용하기 위해 내부에 걸쳐 있어야한다는 것입니다. 링크를 빌드하기 위해 Nice 메뉴에서 사용하는 Drupal 함수 menu_item_link를 편집하기 위해 찾을 수있는 모든 각도를 시도했습니다.

예를 들어, 나는 Drupal 포럼을 이틀 동안 보았습니다.

링크를 빌드하는 모듈의 선은 다음과 같습니다.

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;
}

볼 수 있듯이 $ output을 사용하여 Menu_ITEM_LINK를 사용하여 배열을 링크로 구문 분석하고 Active 클래스를 선택한 내비게이션 링크에 추가합니다.

문제는 A 태그 내부의 스팬을 어떻게 추가합니까, 또는 슬라이딩 도어 링크를 스타일링하기 위해 활성 클래스가있는 스팬으로 태그를 어떻게 래핑합니까?

도움이 되었습니까?

해결책

스팬으로 A 태그를 감싸려면 theme_nice_menu_build 출력에 스팬을 추가하십시오. 태그 내부에 원한다면 덮어 쓰야합니다. menu_item_link.

기능 통화를 만들어 테마 funciton을 덮어 쓸 수 있습니다. your_theme_name_function_name 그리고 Drupal은 그 기능을 사용하여 기본값 대신 마크 업을 렌더링합니다. 그렇게하면 원하는 방식으로 마크 업을 변경할 수 있습니다. 이 기능은 테마의 template.php 파일에 있어야합니다.

시작하는 좋은 방법은 덮어 쓰고 자하는 기능을 복사하고 좋아하는 것으로 바꾸는 것입니다.

Drupal 4.7 이후로 많은 일이 일어났습니다. 나는 당신이 그것을 사용하기를 바랍니다. 스팬 태그를 삽입하는 것은 매우 쉽습니다.

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']);
}

나는 이것을 테스트했고 그것은 잘 작동합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top