导航菜单

本站之前所使用的主题都是用自定义字段存储阅读量的,特别是老博客,阅读量最高的文章足足有38w。
Joe主题是给文章表新增views字段来存储阅读量的。
为了正确显示阅读量,我只能自行修改Joe的代码。

修改教程

找到core/core.php,搜索GetPostViews方法。把$exist = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid))['views'];这一行修改为如下代码就行。

    if ((int)($archive->fields->views) > 0) {
        $row = $db->fetchRow($db->select()->from('table.fields')->where('name = ? and cid = ?', 'views', $cid));
        if (!empty($row)) {
            $exist = $row['str_value'];
            $db->query($db->delete('table.fields')->where('name = ? and cid = ?', 'views', $cid));
            $db->query($db->update('table.contents')->rows(array('views' => (int)$exist))->where('cid = ?', $cid));
        }
    } else {
        $exist = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid))['views'];
    }

代码的作用就是读取自定义字段的值,写入文章表,并删除原来的自定义字段。