方法bai一、修改index.php
<?php if ( have_posts() ) : query_posts($query_string .'&cat=-20,-22');
while ( have_posts() ) : the_post(); ?>
直接在當前主題模板的首頁index.php中修改調出代碼,比如上面的代碼中du是zhi讓20和22分類不顯示出來。
方法二、functions.php修改:這個方法是比較好的,建議使用。
//在首頁中dao排除某些分類
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' );
這個方法直接不會有任何頁面空缺問題,而且在最新內容中也不會出現。直接在當前主題的functions.php添加上面的腳本,修改對應的分類排除。