簡介:
大家都知道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()