Try this plugin. You’ll need the latest nighly.
<?php
/*
Plugin Name: Custom Posts Per Page
Version: 1.0
Plugin URI: http://ww.wp.xz.cn/#
Description: Change the number of posts per page displayed for different page types.
Author: Ryan Boren
Author URI: http://boren.nu/
*/
$num_posts_on_home = 1;
function custom_posts_per_page($query_string) {
global $num_posts_on_home;
$query = new WP_Query();
$query->parse_query($query_string);
if ($query->is_home) {
if ($query_string != '') {
$query_string .= '&';
}
$query_string .= "posts_per_page=$num_posts_on_home";
}
// Category example.
// else if ($query->is_category) {
// if ($query_string != '') {
// $query_string .= '&';
// }
// $query_string .= "posts_per_page=$num_posts_in_category";
// }
return $query_string;
}
add_filter('query_string', 'custom_posts_per_page');
?>
Cheers, thats just the sort of thing i was looking for.
i made one slight change to the ‘if is_home’ section, so that it will replace the existing posts_per_page rather than adding a second (which was getting ignored).
if you care, here is the code:
if ($query->is_home) {
if (preg_match("/posts_per_page=/", $query_string)) {
$query_string = preg_replace("/posts_per_page=[0-9]*/"
,"posts_per_page=$num_posts_on_home"
,$query_string);
} else {
if ($query_string != '') {
$query_string .= '&';
}
$query_string .= "posts_per_page=$num_posts_on_home";
}
}
Does that code go into the plugins folder under wp-content?
Or do you paste it into the index somewhere??
rboren, how would/could I adapt that for posts-by-author?
Wow.. It took me forever to find this but thanks brehaut and rboren this is exactly what I had been looking for and works like a charm!!
Cheers!
This post works great — thanks, Ryan! However, I’ve noticed one oddity — whenever this plugin is activated, the WP admin pages start acting funny. Specifically, pages don’t appear completely after taking an action such as saving a new post or modifying a template — instead, I often get a blank HTML document instead of the WP admin interface. The site itself works fine; it’s just the admin interface that is going screwy, and even that works–it’s just not re-displaying the interface after taking action.
Any ideas out there why this is happening, or how to fix it?
This is EXACTLY what I needed! Works perfectly. Thank you so much! š
Does this plugin mess with feeds? Check this out: http://forums.feedburner.com/viewtopic.php?p=4301#4301
My feeds no longer work. I don’t know why. But I added this plugin around that time.
The reverse order makes sense for most cases, but on the site I’m suing it, I’d like the posts to show in default order. Is there a way to do that with this plugin?
Is there anyway to have the plugin affect only page 1?
Hmm… Changed the if to:
if ($query->is_home && (!isset($_GET['paged']) || $_GET['paged'] == 1)) {
But I’m now missing the 2nd and 3rd posts.
Awesome plugin! Works great! Thanks guys… =)
spencerp
Hi, I was also wondering if this works in WP 2.
Thanks!
Nevermind…tried it, and it’s working.