Amar Syla Amar Syla - 7 months ago 28
PHP Question

Wordpress Loop does not work properly in category.php when using query_posts

I am developing a wordpress theme. I am new in this field, and it's not very easy.

I wrote the code for the loop, and everything is working perfectly. I am working on category.php page. Without the query posts, the category is correctly showing the posts from that specific category.

But, I want to add pagination, and limit the posts per page to maybe 10. But, when I add this code before the loop:

<?php query_posts( 'posts_per_page=10' ); ?>

It doesn't work. Now, it outputs all the posts, from every category in the website, not only from that category.

Can anybody tell me what am I doing wrong?



query_posts( 'cat=3&year=2004' );

You need to add the category to the query_posts; otherwise wordpress won't know you need a category in your custom query.