我們?cè)谧鼍W(wǎng)站的時(shí)候,是不是有些時(shí)候希望某個(gè)分類或者某一些文章不在首頁顯示?因?yàn)槲覀冊(cè)谑醉擄@示的內(nèi)容是稍微要凸顯價(jià)值的,有些沒有價(jià)值的內(nèi)容就不要在首頁顯示。那如何設(shè)置呢?這里,麥子找到可以無需要WordPress插件,即可實(shí)現(xiàn)指定分類或者指定某些文章頁面不在首頁顯示的方法。
1、指定文章不顯示
<?php if ( have_posts() ) : query_posts($query_string .'&cat=-11,-22'); while ( have_posts() ) : the_post(); ?>
這里一般是在index.php主題頁面中調(diào)用頁面文章最新文章列表這里我們調(diào)整禁止幾個(gè)文章的ID。
2、指定分類不顯示
//在首頁中排除某些分類 // http://bjj.org.cn/wpset-nohome.html function exclude_category_home( $query ) { if ( $query->is_home ) { $query->set( 'cat', '-2, -3' ); //你要排除的分類ID } return $query; } add_filter( 'pre_get_posts', 'exclude_category_home' );
這里,我們可以方法來禁止不在首頁顯示的分類。
評(píng)論