Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-09-12 07:35:26

Ericki
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)

Offline

#2 2019-09-12 12:12:59

etc
Developer
Registered: 2010-11-11
Posts: 3,296
Website

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.

Offline

Board footer

Powered by FluxBB