我在头版上有一段欢迎的话。我是用粘帖做的。但是欢迎访问我的网站贴子也显示在我的类别中?有没有办法让它只出现在头版?
我不希望我的头版贴纸出现在某个类别中
2 个回复
SO网友:s_ha_dum
您需要指示查询忽略类别存档上的粘性帖子。
function no_sticky_cats_wpse_125862($qry) {
if ($qry->is_main_query() && $qry->is_category()) {
$qry->set(\'ignore_sticky_posts\',true);
}
}
add_action(\'pre_get_posts\',\'no_sticky_cats_wpse_125862\');
SO网友:Maruti Mohanty
您可以在活动主题的functions.php
文件以完成此操作。
function wpse_125862_exclude_sticky_post( $query ) {
if ( $query->is_main_query() && $query->is_category() ) {
// Will ignore all the sticky posts
$query->set( array( \'post__not_in\' => get_option( \'sticky_posts\' ) );
}
}
add_action( \'pre_get_posts\', \'wpse_125862_exclude_sticky_post\' );
结束