我正在嘗試在我的 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',
);
我在這里錯過了什么嗎?
uj5u.com熱心網友回復:
試試這個:
$the_query = new WP_Query( array( 'cat' => '-17', 'posts_per_page' => '3' ) );
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/461797.html
