Support » Fixing WordPress » Single Post Homepages in 1.3a

  • brehaut


    Hi, I am currently developing a site based around wordpress (1.3a, from the nightlies) that has a single post on the front page. I also want to have 10 posts per page for categories and archive pages.
    Currently, to achieve that I have to set the posts per page to be 10, and just don’t use all of the wordpress loop on the home page (checking it with is_home()). This works, except for two problems.
    Firstly, the previous / next links (generated by posts_nav_link()) will skip 9 posts when the go to the second page.
    Secondly, it must be slightly inefficient to get 10 posts out of the DB and then discard 9 of them. I would quite like to fix that.
    Does anyone have any ideas for a solution to this.
    Andrew Brehaut

Viewing 15 replies - 1 through 15 (of 22 total)
  • Moderator Ryan Boren


    WordPress Dev

    Try this plugin. You’ll need the latest nighly.
    Plugin Name: Custom Posts Per Page
    Version: 1.0
    Plugin URI:
    Description: Change the number of posts per page displayed for different page types.
    Author: Ryan Boren
    Author URI:
    $num_posts_on_home = 1;
    function custom_posts_per_page($query_string) {
    global $num_posts_on_home;
    $query = new WP_Query();
    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]*/"
    } else {
    if ($query_string != '') {
    $query_string .= '&amp;';
    $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!!

    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:

    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… =)


    does this work in WP2???

    Hi, I was also wondering if this works in WP 2.


    Nevermind…tried it, and it’s working.

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Single Post Homepages in 1.3a’ is closed to new replies.