繁体   English   中英

Wordpress 获取不包含类别 ID 的博客文章

[英]Wordpress fetch blog posts excluding a category ID

我正在尝试在我的 wordpress 网站上显示最新的博客文章。 我正在使用这段代码,它显示了任何类别的最新 3 篇博客文章。

<?php 
                
$the_query = new WP_Query( 'posts_per_page=3');     
while ($the_query -> have_posts()) : $the_query -> the_post(); 

?>



<!-- main content here -->  
<div class="blog-post"> 
<?php echo wp_trim_words( get_the_excerpt(), 20, ' ...' ); ?>
</div> 
        
                
<?php 

endwhile;
wp_reset_postdata();    
                        
?>

现在我想从此脚本中排除一个帖子类别(应排除类别 ID 为 17 的所有帖子。我尝试了以下脚本,但无论哪种方式它都不会显示任何帖子(所有代码保持不变,除了我更改并尝试过的前几行)

这个没有显示任何东西

$the_query = new WP_Query( 'posts_per_page=3', 'cat=-17'); 

尝试使用数组:

$the_query = new WP_Query($argsQuery); 

$argsQuery = array(
    'posts_per_page' => 3,
    'cat' => '-17',
);

我在这里错过了什么吗?

尝试这个:

$the_query = new WP_Query( array( 'cat' => '-17', 'posts_per_page' => '3' ) );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM