Typecho非插件实现文章阅读次数统计
在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)加下边的代码 ...