Support » Fixing WordPress » Home page (non-static) pagination

  • Hi all,

    I’m using the home.php file (due to the need to display home-specific stuff and via a different query) to display posts, 3 per page. If I include pagination via the following code:

    <?php next_posts_link("Next"); ?>

    for example, my URL ends up being which is fine for me, except I get a 404 error. I can’t figure out how best to let this fall through to the home.php template and therefore adjust my query accordingly. Am I missing something obvious? 🙂



Viewing 8 replies - 1 through 8 (of 8 total)
  • esmi


    Forum Moderator

    Are you using a custom query in home.php?

    I’m using the following in home.php at present:

    query_posts($query_string . "&cat=-1&posts_per_page=3");

    I’ve tried adding the whole get_query_var('paged') stuff into the mix, but it doesn’t seem to have an effect. Even with a die() at the top of the file, the page doesn’t seem to get executed… 🙂



    Forum Moderator


    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'cat' => -1,
    	'posts_per_page' => 3,
    	'paged' => $paged

    Cheers for the code 🙂 just tried it and I get the same result – a 404 when trying to go to page 2.

    Could it be anything to do with having the permalinks enabled? I’m using the structure for posts’ individual pages, with /category/category-slug etc for categorised posts. The .htaccess file is the basic one that WP suggests.



    Forum Moderator

    No – custom permalinks shouldn’t create any problem. It’s normally using query_posts without the $paged variable that borks the pagination links. Do you have any other custom queries in that page template?

    No, nothing at all – just the loop as normal. Category paging works fine, which is the strange thing. I use the same loop code for both the home page and the category page (via an include()), just the query changes to restrict to the category for category pages etc, and the home page query as above.

    There’s no other custom queries though. I’d have thought that adding the die() command at the top of home.php would have done something, but this just doesn’t get executed at all when eg /page/2/ is requested.

    OK, so update on the above after a good night’s sleep 😉 after a bit of digging, if I revert the permalink setting to the default, eg then everything works as normal – pagination from the home page generates links of the form for the next page down etc, which is correct.

    If I switch to any of the other provided permalink structures, and update my .htaccess file as suggested, then pagination links are of the form and they don’t work – I get the 404. So it looks like it’s something to do with the permalink setup.

    The base URL for the site is correct ( so I can’t see what else I’m missing!

    Any pointers?

    Cheers 🙂


    I know it’s been a year, but I just had this problem and was trying to find a resolution. I figured out what my problem was and I wanted to share it with others. On the permalinks settings page, for some reason the category base was set to the same name as my blog page. This caused the pagination error as described here.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Home page (non-static) pagination’ is closed to new replies.