How to show all the posts of a category.
Its been quite some time since i have posted on this blog.
Was working on wordpress and just came across a scenario where i had to show all the posts belonging to a particular category.
So here it goes..
WordPress uses category.php as a template file to show category pages. category.php can be modified to show all the posts belonging to that particular category. Now the catch here is that THE WHILE loop used to show all the posts belonging to that category limits the number of posts for a single page to be 10 (by default) & if the category has more than 10 pages, then it adds pagination links at the top and bottom of your page.
How to get rid of this ::
Now if you wan to show all the posts for that category on the single page itself, without any pagination links just do this :
Before the while loop (the one used to loop through all the posts), somehting like this <?php while (have_posts()) : the_post(); ?> , add the following lines –
query_posts( $query_string . ‘&posts_per_page=-1’ );
and after the while loop ends, add –
What we are doing here is, we are modifying the $query_string which the WP was using and changing its $post_per_page param to “-1” (-1 for all the posts), additionally we can specify the value of $post_per_page to whatever number of posts we want & add support for pagination.
To know more about WP pagination stay tuned for my next post.