开发者

Attach class to menu item based on content type in Drupal

I have seen a few functions that allow one to attach classes/ID's to menu items; unfortunately, none of them apply to my use case. What I want to do is assign a class/ID to any menu item based on the content 开发者_高级运维type of the linked item.

For example, I have a content type called "Internal" which is only displayed if the viewer is within the accepted IP range (my way of having intranet pages without having a separate site). I want to style these links differently.

On the same lines, I would like to be able to style external links in the menu as well.

Note, I am aware of the Menu Attributes module (http://drupal.org/project/menu_attributes), which does allow me to assign my own ID's to the menu items, but I want something automated as I have well over 100 content editors on the site. Something like this would ideally be an automated process.


You could load a different theme in the configuration directory. You'd probably need a host name for your IP range.

sites/default/themes/my_theme
sites/intranet.tld/themes/my_theme

You'd avoid duplication by symbolic linking the theme and over writing the html/css you need.

See the documentation in settings.php

That's just one of many ways...


You can add the class in theme_menu_item or theme_menu_item_link (depending on if you want it on the li or the a). Then you need some method of figuring out the content type of a given menu item. Something like node_load(array('path' => $link['href'])) should do the trick (untested).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜