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?
Thanks.
http://codex.wordpress.org/Function_Reference/query_posts
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.
What you'll need to do is set how many posts you want to display on the page via Settings -> Reading and WP should take care of the pagination.
If you theme framework doesn't have a pagination function, I would recommend something like: http://wordpress.org/plugins/wp-pagenavi/ http://wordpress.org/plugins/wp-visualpagination/
Those give you a simple PHP code to put into your theme wherever you want the pagination to show up. The code will have to be put between the endwhile; and endif; inside the loop.
您需要将当前类别的ID动态传递到查询中:
query_posts('posts_per_page=10&cat='.get_query_var('cat'));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.