In this article we will be discussing how to override the “Posts Per Page” in WordPress admin setting for select sections in your blog.
Why Do We Need This ?
I ran across this problem when I decided to modify my “Photography and Art Category”. I wanted to set-up this category like a photo gallery and display only thumbnail images and no written content. You can Click here to see the photo category, but please keep in mind that it may not be completely finished yet. It is still a work in progress.
This blog is set to display 10 posts per page in the “reading” section of WordPress Administration, but for just the photography category … and only this category … I wanted at least 30 post thumbnails to be displayed per page. It would be ineffective to display only 10 thumbnails per page in this category, so I needed to find a way to override my posts-per-page setting.
The Code To Override
You can quite easily override the posts per page setting by using the following code:
<?php query_posts($query_string.’&posts_per_page=35‘);?>
By using the term “$query_string” we are telling WordPress to change query_post ONLY with the information provided. We are not completely overriding all settings of query_posts. In the above code you will need to change the red number to the number of posts you would like to have displayed on that page.
This code needs to be placed on your page before The Loop. For example, your final code may look something like this:
…… Blah blah …. header info …..
<?php query_posts($query_string.’&posts_per_page=35′);?>
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?>
……. blah blah post design settings …….
This override feature is especially helpful for overriding the settings on category.php, archive.php, and search results (search.php) pages. Let’s say you only want to display post titles on your search results page. Everywhere else on your blog you display post excerpts and are displaying 10 posts per page. The search results page could certainly fit more then 10 posts on a page if you are only listing the post titles. With the above code, added to your search.php file, you could display as many post titles as you would like on a page.
If you use category templates ( article here ) like I do, you can easily use the above code to modify each category independantly. Very helpful !
As a side note … while you are working with this string … you can also change the sort order of the posts. WordPress automatically sorts your posts in descending order based upon the date of the post. You can change this to ascending order using the following method:
<?php query_posts($query_string.’&posts_per_page=35&order=ASC’);?>
Changing the sort order may be helpful for those who have a “serialized” category. Perhaps a storyline or series of photos that need to be viewed IN ORDER from the first post on.
More info about “query_posts” can be found on the WordPress site.
Hopefully this article has been a help to those of us who are not “code” addicts. I like to pass-along tidbits of information that might allow non-programmers the ability to modify their own websites. Please keep in mind that I am not a professional programmer but I have been building and modifying websites since 1995 using HTML, cgi, perl, MIVA, PHP, and CSS. Suggestions on other ways to reach the desired goals above are always welcome … please consider leaving a comment !
Always remember to save copies of your original files BEFORE you modify them. This will allow you to easily revert your web site if the changes do not work.
Comments ( leave a comment here ) and thoughts ALWAYS welcome !

- Go ahead and STALK ME – electronically of course – Subscribe Here











This worked like a charm. I don’t want to use any more plugins and have been looking for a code-based solution to this problem for a while. Thank you.
Just a quick note though, Wordpress displays some characters in a code unfriendly format so copy & pasting is an issue. You may want to find a way to display usable code.