开发者

Drupal - Selected Node Highlighting in Views

Drupal Question:

Does anyone have a method of using Views and highlighting a selected/current node.

So for example:

I have a list of articles under a heading:

2009 Articles

Dog Training

Cat Cleaning

Snake Wrangling

The 3 articles are made from the view (ie: latest articles from 2009)... as the user makes new articles, they are automatically added into this view by title.

I now need to find a way, that if a user clicks on say CAT CLEANING.... and the cat cleaning article appears, the CAT CLEANI开发者_如何学运维NG in the view becomes bold (or some CSS indication it's the current article.)

I know this is pretty easy with MENU's, But I don't want to force a user to add new articles into a menu.

Thanks alot, JD


Here is what you need to do:

  1. Look up the class of the view list item (e.g. Dog training) using Firebug
  2. Add CSS for the view list item manually in the theme folder or using something more convenient like the css injector module
  3. The CSS will be something like this

    .view-name .view-name-of-field-here a:active {text-decoration: underline; color: red}

Here we are using the "active" CSS pseudo class to color and underline the link if the URL in the view list item is the same URL as the web page.


You could override whichever Views template you're using (do this by clicking the Theme: Information link on the View editing page), and basically say "if the link to this node is the same as the currently viewed path, then add a 'current' class to it."


  1. In the Context Filters, add "Global:null" and select "Get content ID from URL"
  2. Add a NID field and set "Exclude from display"
  3. Add a Mathematic field who evaluate difference between the both NID : "!1-[nid]"and set "Exclude from display"
  4. Add a class to the field to highlight as "active[expression]" where active0 is the class of the current node.

There is the video tutorial to achieve that: http://youtu.be/0uSfuVmO6zk

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜