<p>Found a solution! Used a plugin &quot;Entry Count&quot;. Great thing <a href="https://putyourlightson.com/plugins/entry-count" rel="nofollow noreferrer">https://putyourlightson.com/plugins/entry-count</a></p>

CC BY-SA 4.0
2022-12-19T22:28:32.283Z
2022-12-19T22:28:32.283Z
Dimi
<p>You can use the core <a href="https://craftcms.com/docs/3.x/dev/functions.html#seq" rel="nofollow noreferrer"><code>seq()</code></a> Twig function for this:</p>
<pre><code>&lt;p&gt;This article has been viewed {{ seq('pageviews:' ~ entry.id) }} times&lt;/p&gt;
</code></pre>
<p>If you want to render the current view count without incrementing it, you can pass <code>next=false</code> to the <code>seq()</code> function. A common use case is doing this conditionally, for example to avoid logged-in users (i.e. content authors) from incrementing the count:</p>
<pre><code>{# Only increment the view count if the user is not logged in #}
{% set incrementPageViews = currentUser is null %}

&lt;p&gt;This article has been viewed {{ seq('pageviews:' ~ entry.id, next=incrementPageViews) }} times&lt;/p&gt;
</code></pre>
<p><strong>Make sure to avoid putting the <code>seq()</code> function inbetween <code>{% cache %}</code> tags!</strong> If you do need to cache the surrounding output, a workaround is using a placeholder string inside the cache, and replacing that cached placeholder for the live output from the <code>seq()</code> function:</p>
<pre><code>{# Set the page views to a variable
{% set pageviews = seq('pageviews:' ~ entry.id) %}

{# Use the replace filter to swap out the cached placeholder string for the live pageviews #}
{% apply replace('%PAGEVIEWS%', pageviews) %}

    {% cache %}
        &lt;p&gt;This article has been viewed %PAGEVIEWS% times&lt;/p&gt;
    {% endcache %}

{% endapply %}
</code></pre>

CC BY-SA 4.0
2022-12-19T16:01:55.707Z
It worked! The counter is working, but I tried to display the number of views in the news list like this: {% for new in news %} {{ new.title }} ({{ seq('pageviews:' ~ new.id, next=false) }})<br /><br />{% endfor %} The code is triggered, a list of news is displayed. But in the news list, each entry has zero views. And also, is it possible to sort by the number of views? Please complete the solution if it is not difficult for you))
Dimi
CC BY-SA 4.0
2022-12-17T12:55:15.453Z
2022-12-17T13:07:28.277Z
2022-12-17T13:07:28.277Z
Mats Mikkel Rummelhoff
<p>Please tell me how to make the number of article views? Is there some free plugin or something else? Or does Craft CMS already have some kind of built-in tool for these purposes?</p>

CC BY-SA 4.0
2022-12-17T16:48:16.223Z
Please don't include "Craft CMS" in the title, this entire site is about Craft CMS. It is redundant and unnecessary to include the CMS name in the title of every post.
Lindsey D
CC BY-SA 4.0
2022-12-17T16:51:51.583Z
Similarly, I'd highly recommend adding **more** tags beyond the basic [tag:craft3] tag. Each of your posts is tagged with only [tag:craft3], which limits their visibility. Consider adding tags which are relevant to the subject of the question.
Lindsey D
<craft3>
How to make the number of article views?
# How to make the number of article views?

(Asked by: username_0 on 2022-12-17)

Please tell me how to make the number of article views? Is there some free plugin or something else? Or does Craft CMS already have some kind of built-in tool for these purposes?

**Tags:** craft3

> **Comments:**
> **username_1**: Please don't include "Craft CMS" in the title, this entire site is about Craft CMS. It is redundant and unnecessary to include the CMS name in the title of every post.  
> **username_1**: Similarly, I'd highly recommend adding **more** tags beyond the basic [tag:craft3] tag. Each of your posts is tagged with only [tag:craft3], which limits their visibility. Consider adding tags which are relevant to the subject of the question.  

---

## 2 answers

### Answer by username_0 on 2022-12-19. Score: 1 | Accepted answer

Found a solution! Used a plugin "Entry Count". Great thing <https://putyourlightson.com/plugins/entry-count>


---

### Answer by username_2 on 2022-12-17. Score: 1

You can use the core seq() Twig function for this:
This article has been viewed {{ seq('pageviews:' ~ entry.id) }} times

If you want to render the current view count without incrementing it, you can pass next=false to the seq() function. A common use case is doing this conditionally, for example to avoid logged-in users (i.e. content authors) from incrementing the count:
{# Only increment the view count if the user is not logged in #}
{% set incrementPageViews = currentUser is null %}

This article has been viewed {{ seq('pageviews:' ~ entry.id, next=incrementPageViews) }} times

Make sure to avoid putting the seq() function inbetween {% cache %} tags! If you do need to cache the surrounding output, a workaround is using a placeholder string inside the cache, and replacing that cached placeholder for the live output from the seq() function:
{# Set the page views to a variable
{% set pageviews = seq('pageviews:' ~ entry.id) %}

{# Use the replace filter to swap out the cached placeholder string for the live pageviews #}
{% apply replace('%PAGEVIEWS%', pageviews) %}

    {% cache %}
        This article has been viewed %PAGEVIEWS% times
    {% endcache %}

{% endapply %}

> **Comments:**
> **username_0**: It worked! The counter is working, but I tried to display the number of views in the news list like this: {% for new in news %} {{ new.title }} ({{ seq('pageviews:' ~ new.id, next=false) }})<br /><br />{% endfor %} The code is triggered, a list of news is displayed. But in the news list, each entry has zero views. And also, is it possible to sort by the number of views? Please complete the solution if it is not difficult for you))  

---

