Counterize IIでカウンタを表示する
by kewi on 11 月.12, 2008, under Memo
Counterize IIを用いたカウンタを設置。
http://www.parlia.net/weblog/post/121.html/より,
couterize.phpに昨日のHit数,昨日のユニークなHit数,ユニークなHit数の合計を表示する関数を追加。
# Returns amount of hits yesterday
function counterize_gethitsyesterday()
{
$today = date("Y-m-d");
$yesterday = date("Y-m-d",strtotime("-1 day"));
$sql = "SELECT COUNT(1) FROM ".counterize_logTable()." WHERE timestamp >= '$yesterday' AND timestamp < '$today'";
$wpdb =& $GLOBALS['wpdb'];
return $wpdb->get_var($sql);
}
# Returns amount of unique hits yesterday
function counterize_getuniquehitsyesterday()
{
$today = date("Y-m-d");
$yesterday = date("Y-m-d",strtotime("-1 day"));
$sql = "SELECT count(DISTINCT ip) FROM ".counterize_logTable()." WHERE timestamp >= '$yesterday' AND timestamp < '$today'";
$wpdb =& $GLOBALS['wpdb'];
return $wpdb->get_var($sql);
}
# Returns amount of unique hits total
function counterize_getuniquehitstotal()
{
$sql = 'SELECT count(DISTINCT ip,date(timestamp)) FROM ' . counterize_logTable();
$wpdb =& $GLOBALS['wpdb'];
return $wpdb->get_var($sql);
}
sidebar.phpに表示部分を追加。
<table style="text-align: left"> <tr> <td>Total : </td> <td><?php echo number_format(counterize_getamount()); ?>Hits (<?php echo number_format(counterize_getuniquehitstotal()); ?> unique users) </td> </tr> <tr> <td>Today : </td> <td><?php echo number_format(counterize_gethitstoday()); ?>Hits (<?php echo number_format(counterize_getuniquehitstoday()); ?> unique users)</td> </tr> <tr> <td>Yesterday : </td> <td><?php echo number_format(counterize_gethitsyesterday()); ?>Hits (<?php echo number_format(counterize_getuniquehitsyesterday()); ?> unique users)</td> </tr> <tr> <td>Latest Week : </td> <td><?php echo number_format(counterize_getlatest7days()); ?>Hits (<?php echo number_format(counterize_getuniquelatest7days()); ?> unique users)</td> </tr> <tr> <td>Online : </td> <td><?php echo number_format(counterize_get_online_users()); ?> users</td> </tr> </table>