I wrote a snippet to do this a while back using Page Hit Counter stats. The client didn’t want to go with a ’popular articles’ section in the end so I didn’t finish the snippet but it did work. I’ll post the code here but as I said, it’s not finished (though it worked) and I’m not a programmer so I’m sure it could be improved a lot. I know there is a better way to connect to the db but this was a rough script. Just create a new snippet and paste the code in.
You can change the output to something other than the unordered list I used. Obviously you need to install Page Hit Counter first and I believe you need to check the box ganesh referred to (Log visits (stats) on the Page Settings tab) on documents you want to record stats for, uncheck it for those you don’t want stats for.
$page = '';
$dbServer = "localhost";
$dbDatabase = "db-name";
$dbUser = "db-username";
$dbPass = "db-password";
$sConn = mysql_pconnect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server");
$dConn = mysql_select_db($dbDatabase, $sConn) or die("Couldn't connect to database");
$sql = "SELECT * FROM modx_page_hit_counter";
$rs = $modx->db->query($sql);
$count = $modx->db->getRecordCount($rs);
if($count < 1) {
$page .= "No records found.";
} else {
// list page hits
$sql = "SELECT phc.page_count, sc.pagetitle, page_id FROM modx_page_hit_counter phc, modx_site_content sc WHERE sc.id = phc.page_id ORDER BY phc.page_count DESC, sc.pagetitle ASC LIMIT 5";
$rs = $modx->db->query($sql);
$page .= '<ul>';
while($row = $modx->db->getRow($rs)) {
$page .= '<li><a href="[~' .$row['page_id']. '~]">'.$row['pagetitle'].' '.$row['page_count'].'</a></li>';
}
$page .= '</ul>';
}
return ($page);