About Counter in Sidebar widget
Please tell me mistakes in my English. | Wordpress « ストーリー

Placement Counter in sideber widget text.
Enable Exec-PHP plugin.

サイドバーにカウンターを設置することになったのですが、
プラグインは高機能なものが多い?ようで
簡単に適当にやりたかったので
Exec-PHP プラグインを入れた後でサイドバーウィジットのTextにサクっと?
<div class="counter">
<?php
 $log = './counter/num.txt';
 $icons = './counter/icon';

 $tag[0] = "<img src=\"" . $icons . "/c0.png\" title=\"0\" alt=\"0\">";
 $tag[1] = "<img src=\"" . $icons . "/c1.png\" title=\"1\" alt=\"1\">";
 $tag[2] = "<img src=\"" . $icons . "/c2.png\" title=\"2\" alt=\"2\">";
 $tag[3] = "<img src=\"" . $icons . "/c3.png\" title=\"3\" alt=\"3\">";
 $tag[4] = "<img src=\"" . $icons . "/c4.png\" title=\"4\" alt=\"4\">";
 $tag[5] = "<img src=\"" . $icons . "/c5.png\" title=\"5\" alt=\"5\">";
 $tag[6] = "<img src=\"" . $icons . "/c6.png\" title=\"6\" alt=\"6\">";
 $tag[7] = "<img src=\"" . $icons . "/c7.png\" title=\"7\" alt=\"7\">";
 $tag[8] = "<img src=\"" . $icons . "/c8.png\" title=\"8\" alt=\"8\">";
 $tag[9] = "<img src=\"" . $icons . "/c9.png\" title=\"9\" alt=\"9\">";

 $fh = fopen($log, 'r');    // いままでの人数を読み込む
 flock($fh, LOCK_EX); // 排他ロック
 $num = rtrim(fgets($fh));        // 総数
 fclose($fh);

 $num++;

 $fh = fopen($log, 'w');
 flock($fh, LOCK_EX); // 排他ロック
 fwrite($fh, "$num\n");
 fclose($fh);

 $n0 = sprintf("%08d", intval($num));
 $cnt = strlen($n0);
 for ($i = 0; $i < $cnt; $i++) {
 $c = substr($n0, $i, 1);
 $html .= $tag[$c];
 }
 //print $num;
 print $html;
?>
</div>

Fri Oct 16 2009 19:01:34 | Please tell me mistakes in my English. and Wordpress | No Comments »

Trackback URI | Comments RSS

コメントをどうぞ