在functions.php中加入下面代码
1//get_post_view($this)
2function get_post_view($archive)
3{
4 $cid = $archive->cid;
5 $db = Typecho_Db::get();
6 $prefix = $db->getPrefix();
7 if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) {
8 $db->query('ALTER TABLE `' . $prefix . 'contents` ADD `views` INT(10) DEFAULT 0;');
9 echo 0;
10 return;
11 }
12 $row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid));
13 if ($archive->is('single')) {
14 $db->query($db->update('table.contents')->rows(array('views' => (int) $row['views'] + 1))->where('cid = ?', $cid));
15 }
16 echo $row['views'];
17}
在需要显示次数的地方(如index.php,post.php,page.php)加下边的代码
1<?php get_post_view($this) ?>
这个方法使用的数据和Hanny的Stat插件使用是同一个,可以方便替换掉Star插件,当然你也可以自行修改代码中所引用的数据列。