D7: Add a class to a list item when the created date is less than 14 days old Using Drupal 7 and Views, I currently have a view that produces a list of 5 teasers of the content type &quot;News.&quot; 5 teasers is a hard rule. I'd like to conditionally format the rows so that when their &quot;created date&quot; is less than 14 days old so that I may styles them as &quot;New&quot; with CSS styles. So if there are 3 &quot;New&quot; rows, the balance are 2 unmarked rows.
How to do so?
Update
I had the idea of using the &quot;time ago&quot; date format to populate the class name. However, the format for &quot;time ago&quot; changes. Unfortunately, I can't set the granularity to &quot;days&quot; which would have allowed me to add the text as a class, i.e., date1 through date24 for the past 2 weeks.
Update #2
My genesis subtheme is ignoring any preprocessor routines, see more here. However, I can add the routine to my base template.php.
Update #3
Thanks to Елин Й. for the working code:
function genesis_preprocess_views_view_list(&amp;$variables) {
  $view = $variables['view'];
  if ($view-&gt;name == 'recent_news_widget') {
    foreach ($view-&gt;result as $key =&gt; $result) {
      if (time() - strtotime($result-&gt;node_created_day) &lt; 14 * 24 * 60 * 60) {
        $variables['classes'][$key][] = 'new';
        $variables['classes_array'][$key] = isset($variables['classes'][$key]) ? implode(' ', $variables['classes'][$key]) : '';
      }
    }
  }
}

In an offline discussion, Елин Й. explains why this works; &quot;I took a look in the views theme.inc and found out that, the classes array is flattened to another variable called 'classes_array' you need to do it as well in order to get your new class also added in this array.
You can do that using a preprocessor function for the view you created. You need to preprocess the view and check the creation date of nodes for each row and give them a relating class. 

Given that your view's machine name is recent_news_widget, your diplay format is HTML lists, and your theme name is genesis. You need to use template_preprocess_views_view_list() function in /sites/all/themes/genesis/template.php file

genesis_preprocess_views_view_list(&amp;$variables) {
  $view = $variables['view'];
  if ($view-&gt;name == 'recent_news_widget') {
    // dpm($view);
    // Here comes your logic
  }
}


In the above code you see 2 lines commented out. First one is a helpful function for developers to print out the given array/object/string etc in a browsable style. This function comes with Devel module, which I would strongly recommend to install it.

After browsing the variables, you will probably find where the results are listed and where the classes for the rows are assigned. You need to browse the variables until you find all values you need to build your logic to assign new classes, for example the 'created date' of the node. After you have all the variables you need, you can loop through the results, check the creation date and add a relating class.

UPDATE:
The preprocess functions for other display types than HTML List:

Grid: template_preprocess_views_view_grid()
Table: template_preprocess_views_view_table()
Unformatted: template_preprocess_views_view_unformatted()

UPDATE #2 (According the discussion on chat and your updates on the question):
I find the code in your Update #3 was in the right direction, but with a few mistakes. The corrected version should look like that:

function genesis_preprocess_views_view_list(&amp;$variables) {
  $view = $variables['view'];
  if ($view-&gt;name == 'recent_news_widget') {
    foreach ($view-&gt;result as $key =&gt; $result) {
      if (time() - strtotime($result-&gt;node_created_day) &lt; 14 * 24 * 60 * 60) {
        $variables['classes'][$key][] = 'new';
        $variables['classes_array'][$key] = isset($variables['classes'][$key]) ? implode(' ', $variables['classes'][$key]) : '';
      }
    }
  }
}


The 2 mistakes in your code were:


You passed the argument as &amp;$variables to the function, but used $vars to assign classes, $vars is not defined in the function so the class was not added.
You wanted to use the key number of the result but in foreach you loop only through the values, and $result variable is an object. In the corrected version of your code above, I used $key =&gt; $result by defining the loop so that I can access the key number as well.


UPDATE #3 I added a new line that flattens the classes into classes_array.