Skip to content

Commit

Permalink
修复Typecho1.2.1勾选不上设置的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jrotty authored Jan 14, 2024
1 parent a8bc94f commit dcec4af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 10 additions & 5 deletions CateFilter/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package CateFilter
* @author Rakiy
* @version 1.2.3
* @version 1.2.4
* @link
*/
class CateFilter_Plugin implements Typecho_Plugin_Interface
Expand Down Expand Up @@ -38,8 +38,14 @@ public static function deactivate(){}
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form){
$CateId = new Typecho_Widget_Helper_Form_Element_Text('CateId', NULL, '0', _t('首页不显示的分类'), _t('多个请用英文逗号隔开'));
$form->addInput($CateId);

Typecho_Widget::widget('Widget_Metas_Category_List')->to($categories);
while($categories->next()){$cate[$categories->mid]=$categories->name;}//获取分类列表

$CateId = new Typecho_Widget_Helper_Form_Element_Checkbox('CateId',
$cate,[], _t('勾选首页不想显示的分类'), NULL);
$form->addInput($CateId->multiMode());

}
/**
* 个人用户的配置面板
Expand All @@ -66,9 +72,8 @@ public static function personalConfig(Typecho_Widget_Helper_Form $form){}
public static function filter($obj, $select){
//if('/feed' == strtolower(Typecho_Router::getPathInfo()) || '/feed/' == strtolower(Typecho_Router::getPathInfo())) return $select;
$CateIds = Typecho_Widget::widget('Widget_Options')->plugin('CateFilter')->CateId;
if(!$CateIds) return $select; //没有写入值,则直接返回
if(empty($CateIds)) return $select; //数组为空,则直接返回
$select = $select->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')->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');
$CateIds = explode(',', $CateIds);
$CateIds = array_unique($CateIds); //去除重复值
foreach ($CateIds as $k => $v) {
$select = $select->where('table.relationships.mid != '.intval($v))->group('cid');//确保每个值都是数字;排除重复文章
Expand Down
5 changes: 4 additions & 1 deletion CateFilter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
***

##版本
1.2.3
1.2.4

##说明
首页过滤指定分类

##历史更新

V1.2.4 2024.01.14
修复Typecho1.2.1勾选不上设置的问题

V1.2.3 2022.04.03
删除原作者失效域名,优化一处写法

Expand Down

0 comments on commit dcec4af

Please sign in to comment.