1、获取不想显示的分类ID
这个ID号可以在后台的“文章 -> 分类目录”中获取,当鼠标放到某个分类目录时,浏览器底部的状态栏会显示类似“category&tag_ID=6&post_type=post
”这样的链接,其中的“6”就是这个分类的ID。
特定分类的ID
应该很容易找到的,主要是下面的代码。
2、在主题index.php(现在应该是loop.php了)使用代码
假如我们要在首页隐藏ID为7和243的分类下的文章,可以在首页主题循环开始的地方加入query_posts($query_string .'&cat=-7,-243');
,代码如下:
<?php if ( have_posts() ) : query_posts($query_string .'&cat=-7,-243'); ?>
<?php while ( have_posts() ) : the_post(); ?>
有的人会简写成:
<?php if ( have_posts() ) : query_posts($query_string .'&cat=-7,-243'); while ( have_posts() ) : the_post(); ?>
效果是一样的。
以上代码是通用的,所以就直接公布给大家了。