I'm relatively new to craft, but thanks to this board I am making great progress :-) But here is my first question, which is not answered in here:

I would like to get the count of entries of a certain section, which have been published since the last visit of a user. I'm pretty sure I have to somehow use a cookie for this, but am completely unaware of how to do this in combination with twig :(

  • Are you talking about logged in users?
    – carlcs
    Feb 15, 2018 at 10:16
  • Sorry for being unclear about this. I mean normal, frontend visitors without any account. Feb 15, 2018 at 10:17

1 Answer 1


You can use the cookies Plugin (or for Craft 2) to store the value of the timestamp when the users has visited the page for the last time. Or you can create your custom code like explained in the question: How to set a cookie

You can get the current timestamp like it's stated in the docs

{% set currentTimestamp = now|date('U') %}

And store the cookie like explained

{# Set the cookie using 'set' variable #}
{% do craft.cookies.set( NAME, VALUE, DURATION, PATH, DOMAIN, SECURE, HTTPONLY) %}
{% set yourTimeStamp = getCookie( NAME ) %}

Then you'll search for entries after the specific date

{% set newEntries = craft.entries.postDate('>= ' ~ yourTimeStamp)|length %}

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.