修改模版文件
找到相關模版文件,修改:
<?php if(have_posts()): query_posts($query_string .'&cat=-20,-22');
while(have_posts()): the_post();?>
讓20和22分類不顯示出來。
修改functions.php(推薦)
//在首頁中排除某些分類
function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-20, -22' ); //你要排除的分類ID
}
return $query;
}add_filter( 'pre_get_posts', 'exclude_category_home' );
寫法2:
function exclude_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '-6, -7' );
}
}
add_action( 'pre_get_posts', 'exclude_category' );