Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 546045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:49:32+00:00 2026-05-13T10:49:32+00:00

I’m trying to dream up a way to institute color coding in Drupal views.

  • 0

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…

  1. 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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:49:32+00:00Added an answer on May 13, 2026 at 10:49 am

    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:

    <?php
    // $Id: views-view-table.tpl.php,v 1.8 2009/01/28 00:43:43 merlinofchaos Exp $
    /**
     * @file views-view-table.tpl.php
     * Template to display a view as a table.
     *
     * - $title : The title of this group of rows.  May be empty.
     * - $header: An array of header labels keyed by field id.
     * - $fields: An array of CSS IDs to use for each field id.
     * - $class: A class or classes to apply to the table, based on settings.
     * - $row_classes: An array of classes to apply to each row, indexed by row
     *   number. This matches the index in $rows.
     * - $rows: An array of row items. Each row is an array of content.
     *   $rows are keyed by row number, fields within rows are keyed by field ID.
     * @ingroup views_templates
     */
    ?>
    <table class="<?php print $class; ?>">
      <?php if (!empty($title)) : ?>
        <caption><?php print $title; ?></caption>
      <?php endif; ?>
      <thead>
        <tr>
          <?php foreach ($header as $field => $label): ?>
            <th class="views-field views-field-<?php print $fields[$field]; ?>">
              <?php print $label; ?>
            </th>
          <?php endforeach; ?>
        </tr>
      </thead>
      <tbody>
        <?php foreach ($rows as $count => $row): ?>
          <tr class="<?php print implode(' ', $row_classes[$count]); ?> <?php
            if(stripos($row["created"], "Week")) {
                    print "week-class ";
            }
            if(stripos($row["created"], "Day")) {
                    print "day-class ";
            }?>
            ">
            <?php foreach ($row as $field => $content): ?>
              <td class="views-field views-field-<?php print $fields[$field]; ?>">
                <?php print $content; ?>
              </td>
            <?php endforeach; ?>
          </tr>
        <?php endforeach; ?>
      </tbody>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.