Statistics show the number of articles read Typecho

# Console / Appearance / Edit current look / functions.php in the rearmost adding the following code

 

# Code has been added to the cookie authentication, so that the article is more authenticity Views

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')) { $views = Typecho_Cookie::get('extend_contents_views'); if(empty($views)){ $views = array(); }else{ $views = explode(',', $views); } if(!in_array($cid,$views)){ $db->query($db->update('table.contents')->rows(array('views' => (int) $row['views'] + 1))->where('cid = ?', $cid)); array_push($views, $cid); $views = implode(',', $views); Typecho_Cookie::set('extend_contents_views', $views); //记录查看cookie } } echo $row['views']; }

# Need to display the number of places (such as index.php, post.php) adding the following code

 阅读 <?php get_post_view($this) ?>

Example: index.php

Example: post.php

Guess you like

Origin www.cnblogs.com/vbyyuuy/p/12026511.html