刚遇到一个问题,就是我的 Typecho 博客系统首页想隐藏指定的某一分类或多个分类的文章,希望能在尽可能保持性能的前提之以下实现,请问有相关代码吗?
对了,首页文章列表不显示,但是首页侧边栏也就是 sidebar 上还是要显示的!
我在用的代码,不影响侧边栏:<?php while ($this->next()): ?><?php$hideCates = array(4,5); // 要隐藏的分类ID,单个或多个都可以$skip = false;foreach ($this->categories as $cate) { if (in_array($cate['mid'], $hideCates)) { $skip = true; break; }}if ($skip) continue;?><!-- 正常输出文章相关代码 --><?php endwhile; ?>
以上是使用id,如果是使用分类别名slug,那么代码是:
<?php while ($this->next()): ?>
<?php
$hideSlugs = array('private', 'hidden');//分类别名
$categories = $this->categories;
$skip = false;
foreach ($categories as $cate) {
if (in_array($cate['slug'], $hideSlugs)) {
$skip = true;
break;
}
if ($skip) continue;
?>
<!-- 正常输出文章相关代码 -->
<?php endwhile; ?>