首页 » 收集 » 正文内容
Typecho不显示(隐藏)某个特定分类
寻梦xunm| 667| 收集
3年前
超过1103天 温馨提示
本文最后更新于2021年09月13日,已超过1103天没有更新,若内容或图片失效,请留言反馈。

最近在对钛导航进行改版,需要实现不显示某个特定分类的功能,查看typecho官方文档毫无头绪,在网上查询到的代码也无法实现隐藏分类功能,最后误打误撞实现。

typecho现有的输出所有分类

$this->widget('Widget_Metas_Category_List')

网上查到的相关代码,其中ignore表示要隐藏的分类mid

$this->widget('Widget_Metas_Category_List','ignore=1')

但通过上面的代码无法实现隐藏功能,查看系统文件,最后在/var/Widget/Metas/Category/Edit.php中看到了下面这段代码

/** 父级分类 */
$options = array(0 => _t('不选择'));
$parents = $this->widget('Widget_Metas_Category_List@options', 
    (isset($this->request->mid) ? 'ignore=' . $this->request->mid : ''));
 
while ($parents->next()) {
    $options[$parents->mid] = str_repeat('    ', $parents->levels) . $parents->name;
}

这代码看着很熟悉有木有,上面有个@options的字符串不知道是啥,毕竟PHP盲,尝试把@options加进去,KO,搞定!

最后的代码

<?php $this->widget('Widget_Metas_Category_List@options','ignore=1')->to($categories); ?>

版权声明:本文为博主原创文章,转载请注明出处:https://www.seogo.me/typecho/172.html

0 赞 or 打赏
喜欢就打赏一点
微信 支付宝
隐私
Q Q:1340326824
邮箱:vipshiyi@qq.com
QQ群:422720328

我的音乐

微博客-专为自己编写开发的源码