3

I use a panel with views on the home page of my drupal site (workaround.org). But I would like to put a "new" label in front of any article that was created or edited in the past 2 weeks. The view field "Node: has new content" did not help me because it will flag any content as "new" for anonymous users. Instead I just want to show anonymous users what content has been added recently.

  • Can't you use the creation date? eg. all post from the last 3 days are new. – Neograph734 Nov 19 '12 at 18:37
  • do you use date criteria? – monymirza Nov 20 '12 at 4:58
4

I have some suggestions, ranked below sort of from simple to complex.

  1. You can simply add a static text field to the view, write "New" in the text field, and then filter the view to contain only content from the period you want to have the "New" label on them.
  2. If you want the same list to also display more content, create an attachment display in the same view, override the text field and the date filter, and set the display to attach after the first one.
  3. Use the Theme information in the view to directly override the views output. Find the content id in the template, load the node, and check the creation date.
  4. Render the content through a view mode instead of on a field by field basis. In the the node-template, you can now check the creation date of the node and output the label. This solution would possibly benefit from an added 'per-view-mode' theme suggestion.
0

You can make use of the Views PHP module to write a small custom code that will check if node creation date is within the last two weeks, and then print a label.

Something like this (I'm using [pseudo field names], you need to check which is correct ones)

$show_date = time() - (60*60*24*7*2); //time minus 2 weeks
if ($data->[node_updated_date] <= $show_date) {
  print '<span class="new-label">New</span>';
}

To see which field names to use, you can get the content of the $data object by using the devel modules' dpm($data);

It is adviced not to use the Views PHP module too much, but I never ran into problems using it for small snippets like this.

-1

Views by default provide this functionality for the new content

You just need to select the field(Content: Has new content) in views, it will add a div with unique class and with text "new"

it works with individual user, means if user is watching it first time then only for that user new tag will appear

I hope this will help you. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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