I'm trying to find an alternative to the "Node: has new content" filter and fields provided in Views 2.0
Does anyone know if there's any modules that tag new or updated content from a timestamp based value? For example, being able to set content to be tagged as "updated" or "new" in views based on the node being updated/created in X amount of days from NOW.
I need anonymous users to be able to see the new or updated tags, thereby making the current views method unusable.

Comments

gotcha41’s picture

subscribing

stinky’s picture

subscribing

stinky’s picture

I got this working with views. You'll need the views_customfield module installed.

In you view field, select "Node: Post date" and check "Exclude from display."
Then add a customfield.

In the "Value" section copy/paste the code below. Note the number 4 represents 4 weeks, so change it accordingly.

<?php
$mydate = date('Y-m-d h:i:s', $data->node_created);
$expire = strtotime("+1 week");
$expire = date('Y-m-d h:i:s', $expire);
$difference = date_difference($mydate, $expire, 'weeks', DATE_DATETIME);

if ( $difference <= 4)  {
 print "new";
}else{
print "";
}

?>
begun’s picture

I have created a module which extends the "Node: Has new content" widget in views. With it markers will persist for New or Updated content for a set period of time for anonymous users. The period of time is set through the UI. For logged in users the "Node: Has new content" field will function as normal. Can see project page here (http://drupal.org/project/views_ephemeral_field).

benahlquist’s picture

Stinky, your solution worked perfectly, thank you so much!

Begun, your solution wasn't a bad approach either, but I don't think the "Node: Has new content" widget does quite what I'm looking for.

All I needed was to inject the following on any content in my view that was new in the past 2 weeks; no interest in showing this on stuff that hadn't been clicked on yet.

<span class="some-class">New!<span>

Thanks all for your efforts!

-ben

stongo’s picture

Two great solutions to this issue. Thanks so much, I think lots of people could find this useful.

janekD7’s picture

Thanks stinky for an idea which has let me write my own code for Drupal 7. I would like to point out that for working solution I have to install views php and change code to not to use date_difference which seems to be unavailable in Drupal 7 Date API (or maybe I made some mistakes which makes date_difference unavailable).
Here is my solution:

  $now = time();
  $diff = abs($data->node_created - $now);
  $days = floor($diff / (60*60*24));

  if($days <= 7)
    print "new";

I placed this code inside Global:PHP field in 'Output code' section. It simply prints 'new' for every node that isn't older than 7 days ago.
$diff is the difference in seconds between now and node creation.