<p>You can use the <a href="https://github.com/nystudio107/craft-cookies" rel="nofollow noreferrer">cookies</a> Plugin (or <a href="https://github.com/lewisjenkins/craft-lj-cookies" rel="nofollow noreferrer">for Craft 2</a>)  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: <a href="https://craftcms.stackexchange.com/questions/648/prescribed-way-to-set-cookies-from-plugin-or-twig">How to set a cookie</a></p>

<p>You can get the current timestamp like it's stated in the <a href="https://craftcms.com/docs/templating/datetime#see-also" rel="nofollow noreferrer">docs</a> </p>

<pre><code>{% set currentTimestamp = now|date('U') %}
</code></pre>

<p>And store the cookie like <a href="https://github.com/nystudio107/craft-cookies#setting-cookies" rel="nofollow noreferrer">explained</a></p>

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

<p>Then you'll search for entries <a href="https://craftcms.stackexchange.com/questions/2083/fetch-all-entries-with-dateupdated-after-a-given-time">after the specific date</a></p>

<pre><code>{% set newEntries = craft.entries.postDate('&gt;= ' ~ yourTimeStamp)|length %}
</code></pre>

CC BY-SA 3.0
2018-02-15T10:57:58.077Z
2018-02-15T21:04:01.367Z
2018-02-15T21:04:01.367Z
Robin Schambach
<p>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:</p>

<p>I would like to get the count of entries of a certain section, which have been published <strong>since the last visit of a user</strong>. 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 :(</p>

CC BY-SA 3.0
2018-02-15T10:16:40.947Z
Are you talking about logged in users?
carlcs
CC BY-SA 3.0
2018-02-15T10:17:36.483Z
Sorry for being unclear about this. I mean normal, frontend visitors without any account.
Michal Mladekson
<entries><count>
Get count of new entries since last visit
# Get count of new entries since last visit

(Asked by: username_0 on 2018-02-15)

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 :(

**Tags:** entries, count

> **Comments:**
> **username_1**: Are you talking about logged in users?  
> **username_0**: Sorry for being unclear about this. I mean normal, frontend visitors without any account.  

---

## 1 answers

### Answer by username_2 on 2018-02-15. Score: 1 | Accepted answer

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 %}


---

