質問

私はテキストスライドドアCSSの丸めを使用していますDrupalのテーマにドロップダウンメニューに追加しようとしています。

現在のバージョンでは正常に動作され、Aタグにスパンの主要リンク注射を使用しています。しかし、ドロップダウンメニューをサポートしていません。

の作業コード:

<?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タグを選択した状態のマークアップを可能にするために内部のスパンを持っている必要があるということです。私はリンクを構築するために素敵なメニューで使用されているDrupalの機能menu_item_linkを編集するために見つけることができるあらゆる角度を試してみました。

例えば。私は2日間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;
}
あなたが見ることができるように

$出力はハイパーリンクに変換され、配列を解析するmenu_item_linkを使用して、選択されたナビゲーションリンクにアクティブのクラスを追加します。

問題は、私は、Aタグ内にスパンを追加するか、またはどのように私はスライドドアリンクのスタイルをアクティブなクラスを持っているスパンでAタグをラップはどうすればよいのですか?

役に立ちましたか?

解決

あなたがスパンとAタグをラップしたい場合は、

、あなたはtheme_nice_menu_buildを上書きして出力するようにあなたのスパンを追加することができます。あなたがタグ内にしたい場合は、menu_item_linkを上書きする必要があります。

あなたは創造による関数呼び出しyour_theme_name_function_nameをテーマfuncitonを上書きすることができますし、Drupalは、マークアップの代わりに、デフォルトの1をレンダリングするために、その関数を使用します。そうすれば、あなたはマークアップあなたが好きなように変更することができます。この機能は、あなたのテーマのtemplate.phpファイルである必要があります。

開始するには良い方法は、あなたが上書きし、ちょうどあなたの好みに変更したい機能をコピーすることです。

多くのDrupal 4.7以降起こっている、私はあなたがそれを使用して期待しないでください。これは、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']);
}

私はこれをテストし、それだけで正常に動作します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top