Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

New Member
Registered: 2019-09-12
Posts: 4

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)


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

Registered: 2010-11-11
Posts: 3,989

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:

global $thisarticle;
safe_update('textpattern', 'custom_1=custom_1+1', 'ID='.$thisarticle['thisid']);

Note, however, that bots will flaw the counter, so you could add some code checking user agent and so on.


Board footer

Powered by FluxBB