simple page counters using smarty.get

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Locked
uloloi
Forum Members
Forum Members
Posts: 88
Joined: Thu Dec 16, 2010 8:50 pm

simple page counters using smarty.get

Post by uloloi »

Code: Select all

{if isset($smarty.get.mact)}
  {assign var=mod_action value=","|explode:$smarty.get.mact}
  {assign var=mod_details
          value=["articleid"=>$smarty.get.cntnt01articleid|default:null,
                 "returnid"=>$smarty.get.cntnt01returnid|default:$page_id,
                 "mact"=>$mod_action[0] ]}
  {*<br> DEBUG: {$smarty.server.REQUEST_URI}
    <br>$smarty.get.mact: <pre>{$mod_action|print_r}</pre>
    <br>$mod_details: <pre>{$mod_details|print_r}</pre>*}
{/if}    
{HitCounter opt='hits'}, {HitCounter opt='hosts'} {* Track pages *}
{if isset($entry) && isset($mod_details.articleid)}{HitCounter key1=$mod_details.mact key2=$mod_details.articleid}{/if} {* Track entries ID *}
Hitcounter do the job I just use this chunk into my template to record entries for each page of different modules such as News or CGBlog
Last edited by uloloi on Fri Sep 19, 2014 9:37 pm, edited 1 time in total.
uloloi
Forum Members
Forum Members
Posts: 88
Joined: Thu Dec 16, 2010 8:50 pm

Re: simple page counters using smarty.get

Post by uloloi »

And with this:

Code: Select all

{stats_items} {* CALL UDT, return  smarty var stats_items (array) *}
<pre>{$stats_items|print_r}</pre>
UDT track_items:

Code: Select all

$gCms = cmsms();
$db =& $gCms->GetDb();

$q = "SELECT key1,key2,count(*) as total FROM ".cms_db_prefix()."module_hitcounter GROUP BY key1,key2 ORDER BY total DESC";

$dbresult = $db->Execute( $q );
if( !$dbresult ) echo 'DB error: '. $db->ErrorMsg();

$row_dump = array();

while ($dbresult && $idrow = $dbresult->FetchRow())
{    
	$qrow = new StdClass;
		$qrow->key1 = $idrow['key1'];
		$qrow->key2 = $idrow['key2'];
		$qrow->total = $idrow['total'];
	$row_dump[] = $qrow; 
}

$smarty->assign('stats_items',$row_dump);
Get page count of all items
Locked

Return to “Tips and Tricks”