記事の数が統計関数として読ま増加Typecho

:記事の数は、より一般的にメソッドのトピックに、この機能について話をここで、検索の束を差し込み、統計関数を使用している
テーマのファイルのfunctions.phpに以下のコードを


function Postviews($archive) { $db = Typecho_Db::get(); $cid = $archive->cid; if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) { $db->query('ALTER TABLE `'.$db->getPrefix().'contents` ADD `views` INT(10) DEFAULT 0;'); } $exist = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid))['views']; if ($archive->is('single')) { $cookie = Typecho_Cookie::get('contents_views'); $cookie = $cookie ? explode(',', $cookie) : array(); if (!in_array($cid, $cookie)) { $db->query($db->update('table.contents') ->rows(array('views' => (int)$exist+1)) ->where('cid = ?', $cid)); $exist = (int)$exist+1; array_push($cookie, $cid); $cookie = implode(',', $cookie); Typecho_Cookie::set('contents_views', $cookie); } } echo $exist == 0 ? '暂无阅读' : $exist.' 次阅读'; }

次にホームindex.phpを、post.phpたり、通話の出力音量読みたい他の記事ページ<?php Postviews($this); ?>(記事のページを呼び出す必要があり、か数えることができない)にします。

おすすめ

転載: www.cnblogs.com/ttyytuy/p/12011945.html