0

I want to put a new icon next to node listed in a block if it was created/updated or commented on in last 1 day. I'm able to fetch all the nodes which were created/updated or commented on sorted in descending order of their time of creation/update or comment.

This is my code in template.php:

 function analytic_preprocess_views_view_fields(&$vars) {
     $viewName = $vars['view']->name;
     $view1 = "view1";
     $view2 = "view2";
     $view3 = "view3";

    if (strcasecmp($viewName, $view1) == 0 ||
        strcasecmp($viewName, $view2) == 0 ||
        strcasecmp($viewName, $view3) == 0)
      {
           if (isset($vars['view']->name)) {
              $created = $vars['row']->node_created;
              $changed = $vars['row']->node_changed;

              $cexpire = $created + (1 * 24 * 60 * 60); //one day later
              $uexpire = $changed + (1 * 24 * 60 * 60); //one day later

              if (($cexpire > time()) || ($uexpire > time())) {
                    $vars['newicon'] = '<img src="'. path_to_theme().'/images/new_icon.gif">';
              }
       }
    }
}

Problem is that when I commented on an older article which I created few months back, it was accurately displayed at the top of my block but 'NEW' icon didn't appear next to it and I saw this error on the page:

Notice: Undefined variable: newicon in include() (line 28 of /home/user/public_html/sites/all/themes/analytic/views-view-fields--viewname.tpl.php).

where I'm displaying/rendering this image.

My understanding is that for the node which just has a new comment I don't have the time of update. How do I get that? Like I have node_created and node_changed.

1 Answer 1

1

node_created and node_changed refers only to node itself.

In views you should be able to add relationship " Comment: Last Comment". Then, you'll have filter and field like "Comment: comment time". You can add this field as non-display one and then use it in templates for fields after it. Will be simpler and more reliable than preprocess functions.

Not the answer you're looking for? Browse other questions tagged or ask your own question.