[英]Posts_per_page category wordpress showing 1 post instead of multiple
I guess I am doing something wrong with my loop or my code is broke. 我想我的循环做错了什么,或者我的代码坏了。 I'd like to show all the posts from a specific category. 我想显示特定类别的所有帖子。 Whatever I do, I only see 1 post appearing. 无论我做什么,我只会看到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>
What am I doing wrong here? 我在这里做错了什么?
Your endwhile;
你的endwhile;
is in the wrong place: the code that builds your <li>
tag is outside the loop which is why you're seeing only one post. 位置错误:构建<li>
标签的代码不在循环中,这就是为什么只看到一篇文章的原因。
It should be: 它应该是:
<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.