0

I want to display updated content's field with views block on the front page.

2019/06/20 newly posted content1-title
2019/06/19 updated content2-title

The words updated and newly posted before the title want to customize according to whether the content was first posted or updated. My code is as follows. enter image description here However, even at the time of initial content posting, durpal has different created and changed timestamps, which is not the expected result.
Is there are good ways? Thanks.

0

Views module comes with the field Has new content that outputs New or Updated depending on the status of the node as being viewed by a visitor.

Anonymous visitors don't see anything because there is no history record about that users visits to a particular node.

Authenticated users will see the word New if they never visited that node. If they have visited that node in the past, but the node has been updated in the meantime, they will see Updated. Once they visit the node again, they won't see any output for that field.

So this doesn't work quite as you described in your question, but it still may be what you're after.

You can add that field to your Views, Exclude it from display, and then Rewrite the Title field to include it before the actual title text.

The way you've written your condition in the screenshot is criss-crossed, you're trying to output "updated" for nodes that are new (at least according to your logic of those times being equal).

Your rewrite would also always show output for all nodes, even the ones the visitor has seen. Visitors usually don't expect that to behave like that. That's why it makes more sense to use Has new content field, but it all depends on your project and your visitors' expectations.

The created and updated time always differ because the created time is the one when the Create node form was loaded in the browser, and the updated time is the actual time when the Save button was hit, when the node was actually saved. The difference in created and updated times is the time it takes to fill in the form ;)

  • It is a very informative answer, but my site does not support user login.All users are anonymous. – pims-tak Jun 20 at 8:47
  • Thank you for pointing out my code. It's not the subject, but certainly the logic of if-else was wrong. – pims-tak Jun 20 at 8:49
0

You can 'hide the title' field from the display and afterwards create a php field. The php field can reference the title field if it is declared higher in the list than the php block and then you can use php for your condition.

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.