Textpattern CMS support forum
- New Member
- Registered: 2019-09-12
- Posts: 1
how to have popular posts?
I started using Textpattern a short time ago. So if it’s an obvious question, sorry, I’m learning.
But, how can I have a simple popular posts? Sorted by number of views.
I’m using the latest version of Textpattern
Last edited by Ericki (2019-09-12 07:35:53)
Re: how to have popular posts?
Hi, welcome to the forum.
The easiest way is to increment some custom field (say,
custom1) on each article’s visit and use this field as
sort attribute. You can incorporate this snippet in the relevant page or article form:
<txp:if_individual_article> <txp:php> global $thisarticle; safe_update('textpattern', 'custom_1=custom_1+1', 'ID='.$thisarticle['thisid']); </txp:php> </txp:if_individual_article>
Note, however, that bots will flaw the counter, so you could add some code checking user agent and so on.