[英]posts_per_page=> 0 list all posts for a specific category in wordpress
[英]Posts_per_page category wordpress showing 1 post instead of multiple
我想我的循環做錯了什么,或者我的代碼壞了。 我想顯示特定類別的所有帖子。 無論我做什么,我只會看到1條帖子。
<ol>
<?php
$args = array(
'category_name'=>'test-category',
'posts_per_page' => 15,
'nopaging' => true
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
//Post data
echo get_the_post_thumbnail(get_the_ID());
endwhile;
?>
<li data-href="<?php $trink = get_the_permalink(); echo preg_replace("#/$#im", '', $trink);?>">
<div>
<a class="button" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
</li>
</ol>
我在這里做錯了什么?
你的endwhile;
位置錯誤:構建<li>
標簽的代碼不在循環中,這就是為什么只看到一篇文章的原因。
它應該是:
<ol>
<?php
$args = array(
'category_name' => 'test-category',
'posts_per_page' => 15,
'nopaging' => true
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
//Post data
echo get_the_post_thumbnail(get_the_ID());
?>
<li data-href="<?php $trink = get_the_permalink(); echo preg_replace("#/$#im", '', $trink);?>">
<div>
<a class="button" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
</li>
<?php
endwhile;
?>
</ol>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.