首页排除某些指定分类文章的显示

function exclude_category_home( $query ) { 
if ( $query->is_home ) {//是否首页 
$query->set( 'cat', '-1, -2' ); //排除的指定分类id 
} 
return $query; 
} 
add_filter( 'pre_get_posts', 'exclude_category_home' );

输出指定分类目录的文章

在需要显示的页面添加下面的代码,分类ID和显示篇数请根据实际需求调整。

<ul> 
<?php 
$args=array( 
'cat' => 745, // 分类ID 
'posts_per_page' => 10, // 显示篇数 
); 
query_posts($args); 
if(have_posts()) : while (have_posts()) : the_post(); 
?> 
<li> 
<a href="<?php the_permalink(); ?>" rel="external nofollow" target = "_blank" ><?php the_title(); ?></a>
</li> 
<?php endwhile; endif; wp_reset_query(); ?> 
</ul>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。