设置WordPress网站指定分类内容不在首页显示方法

在帮公司修改网站的时候需要用到的,记录下来以后肯定会用到的  所有还是记录下来

第一、修改functions.php修改

//在首页中排除某些分类
function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( ‘cat’, ‘-6, -6’ ); //你要排除的分类ID
}
return $query;
}
add_filter( ‘pre_get_posts’, ‘exclude_category_home’ );
?>

第一、修改index.php

<?php if ( have_posts() ) : query_posts($query_string .’&cat=-20,-22′);
while ( have_posts() ) : the_post(); ?>