Amar Syla Amar Syla - 1 year ago 92
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?


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download