Warning: Trying to access array offset on value of type bool in /www/wwwroot/zklhy.com/wp-content/themes/twentyfifteen/functions.php on line 544

Warning: Trying to access array offset on value of type bool in /www/wwwroot/zklhy.com/wp-content/themes/twentyfifteen/functions.php on line 553

wordpress网站指定分类不在首页显示

一般来说还是不用到的,但是也是一般来说,这次我就用到了,网站现在对于电影还是比较敏感的所有决定电影以后更新的内容都不在首页显示,废话不多说方法有很多种这里就介绍两种:

第一种:直接修改index.php

把:<?php if ( have_posts() ) : ?>

修改成:

<?php if ( have_posts() ) : is_home() && query_posts($query_string .'&cat=-ID号') ?>

如果你是要屏蔽ID为1的分类就是这样的:

<?php if ( have_posts() ) : is_home() && query_posts($query_string .'&cat=-1') ?>

如果你是要屏蔽ID为1和2的分类就是这样的:

<?php if ( have_posts() ) : is_home() && query_posts($query_string .'&cat=-1,-2') ?>

第二种:functions.php修改

这个方法我比较好一点我用的就是这个

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

这个方法直接不会有任何页面空缺问题,而且在最新内容中也不会出现。直接在当前主题的functions.php添加上面的脚本,修改对应的分类排除。

发表回复