首页 > CMS教程 > WordPress    日期:2019-09-23 / 来自互联网 / 浏览

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

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>

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章