Reputation: 2897
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.
<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?
Upvotes: 0
Views: 232
Reputation: 3948
Your 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.
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>
Upvotes: 2