本站之前所使用的主题都是用自定义字段存储阅读量的,特别是老博客,阅读量最高的文章足足有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'];
}
代码的作用就是读取自定义字段的值,写入文章表,并删除原来的自定义字段。
文章出自:虾米皮皮乐工作室 https://xiamp.net/archives/joe-topic-modification-read-the-article-reading-amount-stored-in-the-custom-field.html,版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。
评论列表(暂无评论)