Page View Counter in MODX EVO Using a TV

Number of page views in MODx EVOFor this search query, nothing was found, I had to write a plugin that counts the number of page views, but not just counts and writes to the database, this record updates to the database. TV parameter.

If you use a simple plugin, we can also filter out news by popularityFor example, display the most viewed pages in MODx EVO.

So, create a TV parameter with the name skolko  and remember it ID, let it be 18 (for example).

Now create a plugin. PageCount And in the plugin code insert a few lines:

global $table_prefix;  

if(!isset($_SESSION['usertype'])) { $_SESSION['usertype'] = ''; }

if($modx->documentObject['donthit'] != 1 && $_SESSION['usertype'] != 'manager') {      

$id = $modx->documentIdentifier;;   

$query = "UPDATE `modx_site_tmplvar_contentvalues` SET value=value+1 WHERE tmplvarid =18 AND contentid=".$id;     

mysql_query( $query);  

}  

return;

The 18 variable is the ID of our TV parameter.

Systemic developments OnWebPagePrerender

And perhaps it is worth saying about a small feature that the amount of page viewing by the manager is not taken into account.


Let’s discuss your project

Tell me what you would like to build. I will reply by email.

Or message me on Telegram @ifwcom