在functions.php中加入下面代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| function get_post_view($archive) { $cid = $archive->cid; $db = Typecho_Db::get(); $prefix = $db->getPrefix(); if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) { $db->query('ALTER TABLE `' . $prefix . 'contents` ADD `views` INT(10) DEFAULT 0;'); echo 0; return; } $row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid)); if ($archive->is('single')) { $db->query($db->update('table.contents')->rows(array('views' => (int) $row['views'] + 1))->where('cid = ?', $cid)); } echo $row['views']; }
|
在需要显示次数的地方(如index.php,post.php,page.php)加下边的代码
1
| <?php get_post_view($this) ?>
|
来源:https://blog.zezeshe.com/