WordPress如何设置首页不显示某个分类下的文章
第一种方法:修改首页index.php代码
首先需要找到不想首页展示文章的栏目ID,在后台栏目列表鼠标放置在某个栏目上,浏览器底部显示的链接中包含此栏目ID,即下图:

找到不想首页展示文章的栏目ID
然后在后台首页代码index.php文件中,找到以下代码:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?> 通常在代码前半部分就能找到 修改
<?php if (have_posts()) : ?>
为
<?php if ( have_posts() ) : is_home() && query_posts($query_string .'&cat=-ID') ?>
其中’&cat=-ID’ 的ID为栏目ID,即你不想首页展示栏目ID。ID可以有多个比如有3个栏目文章不想展示可以这样写
<?php if ( have_posts() ) : is_home() && query_posts($query_string .'&cat=-1,-2,-3') ?>

修改首页index.php代码
第二种方法:修改模板函数 (functions.php)
如果你觉得修改首页PHP代码有难度,又或找不到代码可以用这种方法,这种方法也很简单明了 在模板函数 (functions.php)文件中填写以下代码即可: //在首页中排除某些分类
function exclude_category_home( $query ) { if ( $query->is_home ) { $query->set( 'cat', '-12, -168' ); }
return $query;} add_filter( 'pre_get_posts', 'exclude_category_home' );
其中( ‘cat’, ‘-12, -168’ )所表示的数字即为不想展示的栏目ID。,如果是一个就-12,中间用英文逗号隔开。

修改模板函数 (functions.php)
友情提示:更改代码前备份一下为好,以免出现差错。