0

I have a view (using Views module), which displays a list of all Titles of a custom content type. What I want to do is add a CSS class to the posts that are new (posted within 24 hours for example). I am guessing I need to create a custom module to do this, but am confused where to start. Any help is appreciated.

0

A custom module is almost certainly overkill here. A simpler strategy is a View with an attachment.

Start with your existing view. You need to add a filter to that view so it only shows OLDER content. So add a filter that looks at the relevant date field, e.g. posted, and apply a test such as less than or equal to NOW - 1 day. This will now show all your titles EXCEPT those that are new.

Next add an attachment. Tweak the filter (make sure you apply an This attachment (override) so that your change doesn't affect all displays). This time you want the test to be greater than NOW - 1 day (or whatever period of time is relevant - but it needs to be the inverse, as it were, of the test applied on the first display of the view). Attach the attachment to the first display of your view (page or block as appropriate) and set it to appear BEFORE. This attachment will now show only the NEWER content.

If all that works, you will have the list of titles, both new and old.

The final step is to tweak the CSS. Working on the attachment that has the NEWER entries, go into the field configuration for your title. Again, make sure you select This attachment (override) and not All displays, i.e. that your change will apply only to the attachment and not the initial display as well. You can then adding the name of a custom class in the field configuration (Style Settings, then one or more of the Customize options, then Create a CSS class) and create a class with corresponding name in your style sheet. Or you may be able to apply sufficient tweaks just by using a rewrite.

0

You may want to simply make use of the existing field available in views called:

Content: Has new content values Add that as a field or use it to customize another field, it is pretty handy.

Some more information on what constitutes as NEW or UPDATED: for how long is Content considered "new" by the filter criteria "Content: has new content"?

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.