[英]Post loop repeats by the number of posts
我正在開發一個 wordpress 網站
帖子循環按帖子數重復,如果有 5 個帖子,則重復 5 次
<div class="announc">
<h2> مؤتمرات </h2>
<div class="announc-body">
<ul>
<?php
$args = array(
'cat' => 6,
'posts_per_page' => 2
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata(); ?>
</ul>
</div>
</div>
請幫忙
參數“post_type”是必需的。
$args = [
'post_type' => 'post',
'cat' => 6,
'posts_per_page' => 2,
];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.