Archives page while loop is not working properly. The particular category has 5 posts published. But when I navigate to the archives page for that category it is only displaying 3 posts.
Tried to display number of posts of that particular category using
$count = $GLOBALS['wp_query']->found_posts;
It is returning the proper posts count (total 5 posts).
But when continued to the while loop have_posts()
it is displaying only 3.
Tried wp_reset_query after endwhile, but didn't work.
Also tried with get_categories()
function to display the number of counts in each category it returned correct count but displayed only 3 posts in the while loop.
Below is the archive.php code.
<div class="row">
<?php
while (have_posts()):
the_post();
?>
<div class="col-sm-12 col-md-8">
<div class="blog-post small">
<div class="post-header">
<p class="categories"><a href="#"><?php the_category(', ') ?></a></p>
<h2 class="post-title">
<a href="<? the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<ul class="post-meta">
<li class="date"><?php the_time('F jS, Y') ?></li>
<li class="author">by <a href="<?php the_permalink() ?>"><?php the_author_posts_link(); ?> </a></li>
<li class="comments"><a href="<?php the_permalink() ?>"><?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></a></li>
</ul>
</div>
<div class="post-cover">
<?php
$post_id = get_the_ID();
$meta_info = get_post_meta($post_id, '_thumbnail_id', true);
$image = wp_get_attachment_image_src($meta_info, $size = 'full', $icon = false);
?>
<a href="<?php the_permalink(); ?>">
<img width="367" height="346" src="<?php echo $image[0]; ?>" alt="simple post cover" />
</a>
</div>
<div class="post-body">
<p><?php the_excerpt(); ?></p>
<div class="align-center">
<a href="<?php the_permalink() ?>" class="btn template-btn-2">Read more</a>
</div>
</div>
</div>
</div>
<?php
endwhile;
?>
</div>
What should I do? Any thoughts?
set_query_var('post_per_page', 10);
- I would create a filter, that checks your category and sets the var. – Stender