WordPress.org

Ready to get started?Download WordPress

Forums

Home page (non-static) pagination (9 posts)

  1. richsage
    Member
    Posted 4 years ago #

    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 http://www.example.com/page/2/ 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? :-)

    Cheers,

    Rich

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Are you using a custom query in home.php?

  3. richsage
    Member
    Posted 4 years ago #

    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... :-)

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    Try:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'cat' => -1,
    	'posts_per_page' => 3,
    	'paged' => $paged
    );
    query_posts($args);
  5. richsage
    Member
    Posted 4 years ago #

    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 http://www.example.com/2010/02/01/sample-post/ structure for posts' individual pages, with /category/category-slug etc for categorised posts. The .htaccess file is the basic one that WP suggests.

  6. esmi
    Forum Moderator
    Posted 4 years ago #

    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?

  7. richsage
    Member
    Posted 4 years ago #

    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.

  8. richsage
    Member
    Posted 4 years ago #

    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 http://www.example.com/?p=123 then everything works as normal - pagination from the home page generates links of the form http://www.example.com/?p=2 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 http://www.example.com/page/2/ 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 (http://www.example.com) so I can't see what else I'm missing!

    Any pointers?

    Cheers :-)

    Rich.

  9. michiko23
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic