Here’s a snippet to extend Susans "Page Hit Counter" module and plugin.
Firstly the snippet takes 4 parameters:
[!MostPopular? &excludeIDs=`1,2,3` &limit=`10` &table_prefix=`custom_` &tpl=`your_tpl`!]
Fairly self explanatory, the
&excludeIDs might be useful for 404 pages, Home page etc.
Here’s the snippet code:
<?php
$table_prefix = (isset($table_prefix)) ? $table_prefix : 'modx_';
$limit = (isset($limit)) ? $limit : 5;
$excludeIDs = (isset($excludeIDs)) ? $excludeIDs : '0';
$tpl = (isset($tpl)) ? $tpl : 'top_pages';
$output = '';
$sql = mysql_query('SELECT * FROM `'.$table_prefix.'page_hit_counter`, `'.$table_prefix.'site_content` WHERE '.$table_prefix.'page_hit_counter.page_id='.$table_prefix.'site_content.id AND '.$table_prefix.'site_content.id NOT IN('.$excludeIDs.')ORDER BY `page_count` DESC LIMIT '.$limit.'');
$resultArray = $modx->db->makeArray( $sql );
foreach($resultArray as $item)
{
$params['phc.count']=$item['page_count'];
$params['phc.pageID']=$item['page_id'];
$params['phc.title']=$item['pagetitle'];
$params['phc.longtitle']=$item['longtitle'];
$params['phc.description']=$item['description'];
$output.=$modx->parseChunk(''.$tpl.'', $params, '[+', '+]');
}
return $output;
?>
You will also need a chunk with whichever placeholders you want to use from :
[+phc.count+] [+phc.pageID+] [+phc.title+] [+phc.longtitle+] [+phc.description+]
The default one named
"top_pages" is here:
<p>Total Hits = [+phc.count+] for <a href="[~[+phc.pageID+]~]" title="[+phc.title+]">[+phc.longtitle+]</a> - [+phc.description+]</p>
I haven’t tested it much, but it seems to work okay.
Report back with any problems!
If it works out okay maybe Susan can add it to PHC family.
David