Hi, I am not technically proficient so pls take this comment with a grain of salt, but my friend has implemented a solution that might work well for you. We use hitspage to track hits and pdoResources to output content pages (resources) according to hits. It does not however *display* the number of hits, but just sorts the resources according to number of hits.
I didn't do it myself so I will just put all the files here. I am going to assume that "hitsPageTpl" is the default tpl for hitspage, if needed I can go find it.
We have two snippets, HitsPage and HPCount. HPCount as I remember is necessary but I never understood how it works.
I don't think HitsPage snippet has been changed at all, but here it is in case it has been changed:
$page = $modx->getObject('modResource', $modx->resource->get('id'));
$view = 0;
// Check the option to record in TV
if($saveTv == 'true') {
// get the required TV object by name (or id)
$tv = $modx->getObject('modTemplateVar',array('name'=>'HitsPage'));
if($tv) {
$tvs = $modx->getObject('modTemplateVarResource',array('tmplvarid'=>$tv->id, 'contentid'=>$page->get('id')));
if($tvs) {
$viewTv = $tvs->get('value');
$tvs->set('value',intval($viewTv) + 1);
if($tvs->save()) $view = $viewTv;
} else {
$tvn = $modx->newObject('modTemplateVarResource');
$tvn->set('tmplvarid',$tv->id);
$tvn->set('contentid',$page->get('id'));
$tvn->set('value',1);
if($tvn->save()) $view = 1;
}
}
} else {
$view = $page->getProperty('hitts','hitspage',$view);
}
$page->setProperty('hitts',intval($view) + 1,'hitspage');
$page->save();
return $view;
HPCount is real simple but as I remember very important:
<?php
$modx->hpCount = true;
return '';
And our pdoResource call in the template:
[[!pdoResources?
&parents=`87`
&limit=`8`
&sortbyTV=`HitsPage`
&tvPrefix=``
&tpl=`hitsPageTpl`
&sortdirTV=`DESC`
&sortbyTVType=`integer`
&includeTVs=`1`
&includeTVList=`21`
]]
The call is in a <ul> and I applied styling through the containing <div>
HTH, let me know if you need more info.
EDIT: Ah I forgot the call to HitsPage in the template. Here it is:
<div class="hits-page">Views:[[!HitsPage? &saveTv=`true`]]</div>