WordPress にアクセスカウンターを仕込む。WordPress のアクセスカウンターといえば Counterize II らしい。
wget "http://downloads.wordpress.org/plugin/counterizeii.zip" unzip counterizeii.zip cd counterizeii/
日本語仕様に。
mv counterize-ja_UTF.mo counterize-ja.mo mv counterize-ja_UTF.po counterize-ja.po
昨日のアクセス記録を表示できるように改造。
cp -a counterize.php counterize.php.`date +%Y%m%d%H%M%S` vi counterize.php
--- counterize.php.20100525223204 2008-04-08 11:22:36.000000000 +0900
+++ counterize.php 2010-05-25 22:38:32.000000000 +0900
@@ -238,6 +238,16 @@
return $wpdb->get_var($sql);
}
+# Returns amount of hits yesterday.
+function counterize_gethitsyesterday()
+{
+ $today = date("Y-m-d");
+ $yesterday = date("Y-m-d", time()-86400);
+ $sql = "SELECT COUNT(1) FROM ".counterize_logTable()." WHERE timestamp >= '$yesterday' AND timestamp < '$today'";
+ $wpdb =& $GLOBALS['wpdb'];
+ return $wpdb->get_var($sql);
+}
+
# Returns amount of hits during the last 7 days.
function counterize_getlatest7days()
{
cd ../ sudo cp -a counterizeii /var/www/wordpress/wp-content/plugins/ sudo chown -R apache:apache /var/www/wordpress/wp-content/plugins/counterizeii/
WordPress 管理画面でプラグインを有効化。
テーマのサイドバーとかに組み込んだら完成。
sudo cp -a /var/www/wordpress/wp-content/themes/pclean/sidebar.php /var/www/wordpress/wp-content/themes/pclean/sidebar.php.`date +%Y%m%d%H%M%S` vi /var/www/wordpress/wp-content/themes/pclean/sidebar.php
--- /var/www/wordpress/wp-content/themes/pclean/sidebar.php.20100525224705 2010-01-20 11:00:29.000000000 +0900
+++ /var/www/wordpress/wp-content/themes/pclean/sidebar.php 2010-05-25 22:51:05.000000000 +0900
@@ -8,6 +8,12 @@
</ul>
</li>
<li>
+<h3>カウンター</h3>
+<ul>
+<li>今日 : <?php echo counterize_gethitstoday();?></li>
+<li>昨日 : <?php echo counterize_gethitsyesterday();?></li>
+<li>合計 : <?php echo counterize_getamount();?></li>
+</ul>
<h3>最近の投稿</h3>
<ul>
<?php query_posts('showposts=5'); ?>
