4

私は最近、うまく機能するプライマリ リンクにクラスを追加するテーマ関数を作成しました。次に、カスタムの背景画像でこれらのリンクのスタイルを設定する CSS クラスをいくつか作成しました。うまくいきました。ここで問題が発生します。プライマリ リンクのリンク テキストは引き続き表示されます。通常、カスタムの「非表示」クラスでラップするだけなので、これは問題ではありません。例えば:

<span class="hide"><a href="#">Link Text</a></span>

だから私の質問は、プライマリリンクをループして、私の例のようにテキストをラップするにはどうすればよい<span>ですか? これが、クラスを追加するために使用したテーマ関数です。

function zkc_preprocess_page(&$vars, $hook) {

// Make a shortcut for the primary links variables
  $primary_links = $vars['primary_links'];
// Loop thru the menu, adding a new class for CSS selectors
    $i = 1;

    foreach ($primary_links as $link => $attributes){
        // Append the new class to existing classes for each menu item
        $class = $attributes['attributes']['class'] . " item-$i";
        // Add revised classes back to the primary links temp variable
        $primary_links[$link]['$attributes']['class'] = $class;
        $i++;
        } // end the foreach loop

// reset the variable to contain the new markup
$vars['primary_links'] = $primary_links;

}
4

4 に答える 4

2

リンクテキストを非表示にしたいだけなら、次のようなものを使用してみませんtext-indent: -9999px;か?

于 2010-03-25T19:41:37.647 に答える
2

jQueryはオプションですか?

次のようなことを試してください:

$(document).ready(function(){
  $('#primary li a')
  .wrapInner('<span class="hide">' + '</span>');
});

編集:

または、Drupal に移行したい場合は、この人を foreach ループに入れます。

$link['title'] = '<span class="hide">' . check_plain($link['title']) . '</span>';

于 2010-03-25T19:23:52.203 に答える
1

The correct methods for altering the output of the menu links can be done at the theming layer. You were on the right path with the preprocessing hook use, but there is a little more to it.

Refer to this for more information:

http://drupal.org/node/352924#comment-1189890

http://api.drupal.org/api/function/theme_links/6

于 2010-03-26T01:52:12.263 に答える
0

打ち間違え?

$primary_links[$link]['$attributes']['class'] = $class;

読むべきです;

$primary_links[$link]['attributes']['class'] = $class;

于 2010-03-26T12:42:19.847 に答える