[英]exclude certain categories from posts on wordpress
我有一个页面显示最新的帖子,但是我试图从某些类别中排除帖子。 这是我的代码:
<?php $categories = get_categories( $args ); ?>
<?php
$args = array( 'numberposts' => 2,
'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date", 'exclude'=>"8");
$postslist = get_posts( $args );
echo '<div class="latest_new_posts">';
foreach ($postslist as $post) : setup_postdata($post); ?>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12" >
<div class="blog-date-news"><span><?php the_date('d/m/Y'); ?></span></div>
<div class="blog-container">
<div class="news-blog-title"><span><?php the_title(); ?></span></div>
<div class="news-blog-excerpt"> <?php echo excerpt(500); ?> </div>
</div>
</div>
<?php endforeach; ?>
因此,我尝试从中排除类别ID 8,但仍在显示。 有什么想法我做错了吗?
WordPress不知道您要排除类别,该排除参数用于帖子ID。
从查询中排除类别。 您使用带有减号的“ cat”参数,即“ cat” =>“-8”
排除属于类别ID 8的帖子
$args = array( 'numberposts' => 2,
'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date", 'cat'=>'-8');
资料来源: https : //codex.wordpress.org/Class_Reference/WP_Query#Parameters
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.