方法一、修改index.php
<? php if ( have_posts() ) : query_posts($query_string .'&cat=-20,-22'); while ( have_posts() ) : the_post(); ?> |
直接在当前主题模板的首页index.php中修改调出代码,比如上面的代码中是让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' ); |
这个方法直接不会有任何页面空缺问题,而且在最新内容中也不会出现。直接在当前主题的functions.php添加上面的脚本,修改对应的分类排除。
转载请注明本文链接:https://blog.weixiaoline.com/131.html