Last active
August 29, 2015 14:05
-
-
Save jpdevries/c6c80d27a622d2de946f to your computer and use it in GitHub Desktop.
get the hit count of a single MODX resource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$defaultHitsCorePath = $modx->getOption('core_path').'components/hits/'; | |
$hitsCorePath = $modx->getOption('hits.core_path',null,$defaultHitsCorePath); | |
$hitService = $modx->getService('hits','Hits',$hitsCorePath.'model/hits/',$scriptProperties); | |
if (!($hitService instanceof Hits)) return 'failed'; | |
$s= ''; | |
// pass this into your snippet [[!getHitCount? &resource=`[[**id]]`]] | |
$resource = modx->getOption('resource',$scriptProperties,$modx->resource->get('id')); | |
$c = $modx->newQuery('Hit'); | |
$c->where(array( | |
'hit_key:IN' => $resource | |
)); | |
$c->limit(1); | |
$hit = $modx->getOne('Hit',$c); | |
// assume there's a hit_count chunk containing: [[+hit_count]] | |
$s .= $modx->getChunk('hit_count',$hit->toArray()); | |
return $s; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just seem to get a white screen with this. I noticed you are missing a $ in front of modx in line 11.
I'm also not familiar with the [[**id]] syntax. I thought it was just a sing le asterisk. I'm also wondering how you would use this in an element in a getResources chunk.