通过 CSS 定制 drupal 菜单?

发布于 2024-10-11 23:13:17 字数 324 浏览 3 评论 0原文

我一直在相当成功地摆弄 drupal 主题(或者至少,我是这么认为的),但是当我尝试将 css 编码注入主链接菜单以自定义它(就像我通常通过 html+css 所做的那样)时,我点击了墙。

我已经能够将 css 样式应用于 div、链接和文本,但我想更多地自定义主要(和辅助)链接菜单,也许使用一些 css sprite 菜单技术,但同时保持 drupal 兼容并使用尽可能多的内容drupal自己的php在这个过程中。或者如果我真的必须重写一些代码,我不介意,尽管我还不是程序员。

我浏览过几个网站,但没有任何特别有用的东西,所以如果有人能指出我正确的方向,我将非常感激。

提前致谢。

I've been fiddling around with drupal theming quite succesfully (or at least, that's what i think), but when I tried to inject css coding to the primary links menu to customize it as i generally do via html+css, i hit a wall.

I have been able to apply css styles to divs, links and text, but I would like to customize the primary (and secondary) links menus much more, perhaps with some css sprite menu techniques, but while remaining drupal-compliant and using as much of drupal's own php in the process. or if i really have to rewrite some code, i don't mind, though i am not quite the programmer yet.

i have been around several sites but i haven't anything particularly useful, so if anyone can point me to the right direction, i will be quite grateful.

thanx in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

唠甜嗑 2024-10-18 23:13:17

您可以为每个菜单项添加一个类似 id 的类 - 在 template.php 中添加此函数

function mythemename_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }

  // LOOK HERE
  // add a key for main menu items, so we can theme each item in a different way
  // add this class only for a specific menu
  if ($link['menu_name'] == 'menu-menu-mymenu') {
    if ($link['localized_options']['attributes']['class']) {
      $link['localized_options']['attributes']['class'] .= ' menu-'. $link['mlid'];
    }
    else {
      $link['localized_options']['attributes']['class'] = 'menu-'. $link['mlid'];
    }
  }

  return l($link['title'], $link['href'], $link['localized_options']);
}

此代码可以更清晰,但我添加了更多行,以便您可以更好地阅读它。

You can add a id-like class for each menu item - add this function in your template.php

function mythemename_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }

  // LOOK HERE
  // add a key for main menu items, so we can theme each item in a different way
  // add this class only for a specific menu
  if ($link['menu_name'] == 'menu-menu-mymenu') {
    if ($link['localized_options']['attributes']['class']) {
      $link['localized_options']['attributes']['class'] .= ' menu-'. $link['mlid'];
    }
    else {
      $link['localized_options']['attributes']['class'] = 'menu-'. $link['mlid'];
    }
  }

  return l($link['title'], $link['href'], $link['localized_options']);
}

This code can be cleaner, but i've added more lines so you can read it better.

银河中√捞星星 2024-10-18 23:13:17

如果我正确理解你的问题,你会想在你的菜单中添加一个自定义类/id。这可以通过覆盖给定菜单的 theme_menu_tree 来完成。我通过将以下内容添加到我的 template.php 文件中来为我的主菜单执行此操作:

function THEMENAME_menu_tree__main_menu($variables){
return '<ul class="menu main-menu">' . $variables['tree'] . '</ul>';
}

希望这会有所帮助。

您还应该查看 themer 模块,它为您提供有关模板功能等的建议。

干杯,
约尔根

if I understand your question correctly you will like to add a custom class/id to you menu . This can be done by overriding the theme_menu_tree for a given menu. I do this for my main menu by adding the following to my template.php file:

function THEMENAME_menu_tree__main_menu($variables){
return '<ul class="menu main-menu">' . $variables['tree'] . '</ul>';
}

hope this helps.

You should also have a look at the themer module, which gives you suggestion for template functions and more.

cheers,
Jørgen

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文