魔改typecho系统函数和typecho后台界面

简介:

大家都知道typecho是开源博客,没有开放商店等功能,相当于没有收入,纯属免费开发,所以开发者也不是更新很频繁,所以有很多我们刚需的内容没有添加,现在我就自己添加一些自己喜欢的功能和修改自己喜欢的后台界面,下面会把var核心文件的每一处修改标注,admin文件的修改基本是样式问题,就不具体描述。目前已添加置顶和浏览量,最好配合本博客主题使用。

链接:

具体的代码更新请关注我的博客

图片:

后台截图

修改:

修改一

根据样式问题删掉部分

var/Widget/Users/Profile.php的个人资料删掉

修改二 (添加置顶文章)

1、在var/Widget/Contents/Post文件夹的Recent.php

源代码:

$this->db->fetchAll($this->select()
        ->where('table.contents.status = ?', 'publish')
        ->where('table.contents.created < ?', $this->options->time)
        ->where('table.contents.type = ?', 'post')
        ->order('table.contents.created', Typecho_Db::SORT_DESC)
        ->limit($this->parameter->pageSize), array($this, 'push'));

修改后

$this->db->fetchAll($this->select()
    ->where('table.contents.status = ?', 'publish')
    ->where('table.contents.created < ?', $this->options->time)
    ->where('table.contents.type = ?', 'post')
    ->order('table.contents.order', Typecho_Db::SORT_DESC)
    ->order('table.contents.created', Typecho_Db::SORT_DESC)
    ->limit($this->parameter->pageSize), array($this, 'push'));

2、在var/Widget/Contents/Post文件夹的Edit.php,发布文章函数writePost(),添加oder

 $contents = $this->request->from('password', 'allowComment',
            'allowPing', 'allowFeed', 'slug', 'tags', 'text', 'order', 'visibility');

3、在var/Widget/Archive.php的execute()函数末尾修改为

 $select->order('table.contents.order', Typecho_Db::SORT_DESC, 'table.contents.created', Typecho_Db::SORT_DESC)
            ->page($this->_currentPage, $this->parameter->pageSize);

4、typecho的默认数据库函数不支持两个order by查询,所以我们修改它,找到var/Typecho/Db/Query.php,修改order函数

    public function order($orderby, $sort = Typecho_Db::SORT_ASC)
    {
        if (func_num_args() > 2) {
            $this->_sqlPreBuild['order'] = ' ORDER BY ' . $this->filterColumn($orderby) . (empty($sort) ? null : ' ' . $sort) . ',' . $this->filterColumn(func_get_arg(2)) . (empty(func_get_arg(3)) ? null : ' ' . $sort);
        } else {
            $this->_sqlPreBuild['order'] = ' ORDER BY ' . $this->filterColumn($orderby) . (empty($sort) ? null : ' ' . $sort);
        }

        return $this;
    }

5、界面设置置顶,在admin/write-post.php在标签后面添加即可

<section class="typecho-post-option">
    <label for="order" class="typecho-label"><?php _e('置顶');?></label>
    <p>
        <select id="order" name="order" class="w-100">
            <option value="0" <?php if ($post->order == '0' || !$post->order): ?>
                selected<?php endif;?>><?php _e('否');?></option>
            <option value="1" <?php if ($post->order == '1'): ?> selected<?php endif;?>>
                <?php _e('是');?></option>
        </select>
    </p>
</section>
修改三 (浏览量)

1、在var/Widget/Abstract/Contents.php 的select()函数添加’table.contents.views’字段

public function select()
    {
        return $this->db->select('table.contents.cid', 'table.contents.title', 'table.contents.slug', 'table.contents.created', 'table.contents.views', 'table.contents.authorId',
            'table.contents.modified', 'table.contents.type', 'table.contents.status', 'table.contents.text', 'table.contents.commentsNum', 'table.contents.order',
            'table.contents.template', 'table.contents.password', 'table.contents.allowComment', 'table.contents.allowPing', 'table.contents.allowFeed',
            'table.contents.parent')->from('table.contents');

    }

2、在var/Widget/Archive.php的singleHandle 添加浏览加1;

 //浏览+1
        if ('post' == $this->parameter->type) {
            if (isset($this->request->cid)) {
                $cid = $this->request->cid;
                $views = Typecho_Cookie::get('extend_contents_views');
                if (empty($views)) {
                    $views = array();
                } else {
                    $views = explode(',', $views);
                }
                if (!in_array($cid, $views)) {
                    $row = $this->db->fetchRow($this->db->select('views')->from('table.contents')->where('cid = ?', $cid));
                    $this->db->query($this->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);
                }
            }
        }

3、使用方法,跟其他变量一样使用

$this->views()
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Typecho 是一个简洁、轻量级的开源博客系统,拥有以下优点和缺点: 优点: 1. 简单易用:Typecho界面简洁直观,功能布局清晰,易于使用和上手。 2. 轻量高效:Typecho 的代码精简,加载速度快,占用系统资源较少,适合部署在各种环境中。 3. 安全稳定:Typecho 有较好的安全性和稳定性,经过了多次版本迭代和测试,有活跃的社区支持。 4. 插件丰富:Typecho 提供了丰富的插件库,可以方便地扩展和定制功能,满足个性化需求。 5. Markdown 支持:Typecho 内置对 Markdown 的支持,方便用户使用更加简洁的语法撰写文章。 6. SEO 友好:Typecho 在设计上考虑了搜索引擎优化(SEO),生成的页面结构清晰,有利于搜索引擎索引。 缺点: 1. 主题较少:相比其他博客系统Typecho 的主题数量较少,选择较为有限。 2. 社区相对小众:相对于一些流行的博客系统(如 WordPress),Typecho 的用户群相对较小,社区活跃度可能不如其他平台。 3. 缺乏一些高级功能:Typecho 的设计初衷是简洁高效,因此在某些高级功能方面可能相对欠缺,需要额外的插件或自定义开发来实现。 综合来说,Typecho 是一个适合追求简洁、高效博客系统的选择,特别适合个人博客或小型网站搭建。如果你对博客系统的扩展性和主题选择要求较高,或者需要更多高级功能,可能需要考虑其他更为全面的博客系统

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值