首页index.php

<?php $this->title() ?>

替换成

<?php $this->title(); $this->sticky() ?>
<?php
/**
 * 大武汉自用主题
 * 
 * @package 大武汉
 * @author maxwuhan.com
 * @version 1.0
 * @link https://maxwuhan.com
 */
$this->need('header.php');
?>

替换成

<?php
/**
 * 大武汉自用主题
 * 
 * @package 大武汉
 * @author maxwuhan.com
 * @version 1.0
 * @link https://maxwuhan.com
 */
$sticky = $this->options->sticky; 
if($sticky){
    $sticky_cids = explode('|',$sticky);
    $sticky_html = "<span class='terms-count'><span class='icon-fire'></span></span> "; 
    $db = Typecho_Db::get();
    $select1 = $this->select()->where('type = ?', 'post');
    $select2 = $this->select()->where('type = ? && status = ? && created < ?', 'post','publish',time());
    $this->row = [];
    $this->stack = [];
    $this->length = 0;
    $order = '';
    foreach($sticky_cids as $i => $cid) {
        if($i == 0) $select1->where('cid = ?', $cid);
        else $select1->orWhere('cid = ?', $cid);
        $order .= " when $cid then $i";
        $select2->where('table.contents.cid != ?', $cid); 
    }
    if ($order) $select1->order('', "(case cid$order end)");
    if (($this->_currentPage || $this->currentPage) == 1) foreach($db->fetchAll($select1) as $sticky_post){
        $sticky_post['sticky'] = $sticky_html;
        $this->push($sticky_post); 
    }
    $uid = $this->user->uid; 
    if($uid) $select2->orWhere('authorId = ? && status = ?',$uid,'private');

    $sticky_posts = $db->fetchAll($select2->order('table.contents.created', Typecho_Db::SORT_DESC)->page($this->_currentPage, $this->parameter->pageSize));
    foreach($sticky_posts as $sticky_post) $this->push($sticky_post); 
    $this->setTotal($this->getTotal()-count($sticky_cids)); 
}
$this->need('header.php');
?>

functions.php

添加以下内容

$sticky = new Typecho_Widget_Helper_Form_Element_Text('sticky', NULL, NULL, _t('文章置顶'), _t('置顶的文章cid,多个用 | 隔开'));
$form->addInput($sticky->addRule('xssCheck', _t('请不要使用特殊字符')));