I’m trying to dream up a way to institute color coding in Drupal views. I have several needs for this but can’t figure out how to do it. Here are some examples…
- In a table view for a content type, I want to color code each row based on the age of the post. In other words, “age” of the post is one of the columns in the table, and I want each row whose post is less than a day old to be highlighted with a yellow background. If it’s over a week, highlight with red, and so on…
Anyone have ideas for this? I suspect we could probably grab the conditional values in a normal web page, but this is tricky in Drupal and my javascript knowledge is limited. I know with good ole SQL we could run some PHP on the values and associate a css selector to do this, but I’m trying to accomplish it in views (the contributed modlue).
Thanks in advance
I would create a views-view-table–Temp.tpl.php (where Temp is the view name) that inserts in the classes depending on the date. Here is an example where I changed the created date to show Time Ago and just searched on Week or Day with stripos. You can use php date math or other methods to insert your class. This is very basic and will need tweaking: