思路大概是:
在模板中添加设置项->欲隐藏的分类ID(用英文逗号分割取多个)
在
index.php
重新给文章列队(置顶文章同理)。最后通过分类与文章的关系(typecho文章分类是另外一个表)进行分类筛选。
以下是index.php加入的代码:
//首页隐藏某分类文章
if($this->options->cidId && $this->is('index')){ $this->row = []; $this->stack = []; $this->length = 0; $order = ''; //清空文章队列 $db = Typecho_Db::get(); $restPostSelect = $this->select('table.contents.cid', 'table.contents.title', 'table.contents.slug', 'table.contents.created', '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')->where('table.contents.type = ? and table.contents.status = ? and table.contents.created < ?', 'post','publish',time())->group('table.contents.cid'); $restPostSelect = $restPostSelect->join('table.relationships','table.relationships.cid = table.contents.cid','right')->join('table.metas','table.relationships.mid = table.metas.mid','right')->where('table.metas.type=?','category'); $cidId = explode(',', $this->options->cidId);//分割文本 foreach($cidId as $i => $cid) { $restPostSelect->where('table.relationships.mid != '.intval($cid))->group('cid'); } $endSelect = $restPostSelect->order('table.contents.created', Typecho_Db::SORT_DESC); $rest_posts = $db->fetchAll($restPostSelect->order('table.contents.created', Typecho_Db::SORT_DESC)->page($this->_currentPage, $this->parameter->pageSize)); foreach($rest_posts as $rest_post) { $this->push($rest_post); } $this->setTotal($this->getTotal()-count($cidId));//重新设置文章数 }
在functions.php
同样要加模板设置:
$cidId = new Typecho_Widget_Helper_Form_Element_Text('cidId', NULL, NULL, _t('首页列表不显示的分类ID'), _t('在这里填入欲隐藏的分类ID,使用半角逗号“,”填入多个,如:1,2,留空不显示')); $form->addInput($cidId);
评论 (0)