1

I would like to print "New" if the node author is registered within 4 weeks in a field of "node View" by using custom php with Views Custom Field. I tried the code below but didn't work. Am I missing something?

   <?php
      $four_weeks_ago = time() - (28 * 24 * 60 * 60);

      $user_created_time=$user->created;

    if ( $user_created_time >= $four_weeks_ago) {
        $this_user_is_new="new";
        print $this_user_is_new;
      }
    ?>
2
  • It would be very helpful to know what's in $data, and some information about why the code does not work.
    – Letharion
    Mar 2, 2012 at 15:20
  • I just changed the title and the example code just to make my question more clear and simple. Please let me know if it's still not very understandable. Thanks.
    – chinita7
    Mar 2, 2012 at 17:47

2 Answers 2

1

What if you edit Vikas code with:

$node_author = user_load($node->uid);
$author_created_time = $node_author->created;
0
0

You can try this :

global $user; // contains all information of login user

$four_weeks_ago = time() - (28 * 24 * 60 * 60);

$user_created_time = $user->created; // user registration date

if ( $user_created_time >= $four_weeks_ago) {
    $this_user_is_new="new";
    print $this_user_is_new;
}
1
  • Thanks I tried your code but didn't work. I think this is for "login user" but what I'm trying to do is the user creation date of "node author"
    – chinita7
    Mar 1, 2012 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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