Joe主题修改:读取自定义字段存储的文章阅读量

Typecho教程 2020-12-31 76℃ 0 0

本站之前所使用的主题都是用自定义字段存储阅读量的,特别是老博客,阅读量最高的文章足足有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'];
    }

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

评论 (0)

友情链接
最近评论
  1. Thiết kế phòng hát karaoke : I got this website from my pal who told me on the topic of this site and now this time I am visiting this site and
    reading very informative articles or reviews here.
  2. Lil Durk : Hello I am so grateful I found your website, I really found you by accident, while
    I was researching on Google for something else, Regardless I am here now and would just like to say
    thanks for a marvelous post and a all round exciting
    blog (I also love the theme/design), I don’t have time to read it all at the moment but I have book-marked it and also
    added your RSS feeds, so when I have time I will be back to read more, Please do keep up the superb b.
  3. Sbobet99 : Howdy thiiѕ is kinda of off tօpic but Ι was wondering if blogs use
    WYSIWYG editors or if you have to manually code with HTML.I'm starting a blog so᧐n butt have no coding skills so I wantеd to get guidаnce
    from someone with experience. Any help would be enormously аpprecіated!
  4. choithethao.tips : Undeniably believe that which you said. Your favorite
    justification seemed to be on the net the easiest thing to be aware of.
    I say to you, I certainly get irked while people consider
    worries that they plainly don't know about. You managed to
    hit the nail upon the top and also defined out the whole thing without having side-effects ,
    people can take a signal. Will likely be back to get more.Thanks
  5. https://veviewwii.tumblr.com/post/662643202115944448/ml-18s21-t2-2 : Link exchange is nothing else however it is simply placing the other
    person's web site link on your page at suitable place and other person will also do similar in support of
    you.
Top