Ready to get started?Download WordPress


WP 3.0 bug with pagination? (when using static page as homepage) (21 posts)

  1. mjepson
    Posted 4 years ago #


    Our users have reported trouble with our custom page templates when using a static homepage. The page template has a query_posts with pagination in it. Here is an example for our standard blog page template:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    This worked fine in all our themes in WP 2.9.2, and works fine in WP 3.0 as a normal page:

    Blog page 1: http://cl.ly/6716a2a1fd3e314deac5
    Blog page 2: http://cl.ly/969377b06da3669e9b53

    If you set it up as static page homepage:


    It shows only the page title of that page:


    Exactly the same page template as static homepage in WP 2.9.2:


    I couldn't see any changes on the codex page for query_posts, so I'm thinking this might be a bug?

    Copying the page template (template-blog.php) to home.php works fine as well.

    Another note, it doesn't matter which static homepage you select... It can be a normal page, it doesn't have to be the page template in question. The page template stops working when you set a static homepage.


    If I add cat=& to the query, the page shows, but pagination doesn't work...

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("cat=&paged=$paged"); ?>

    If I echo $paged on /?paged=2 it simply outputs 1

  2. MaXCoDeR
    Posted 4 years ago #

    Actually, it doesn't simply work with with even <?php wp_link_pages(); ?>

    When I click on the 2nd page link, it displays the first page.

  3. MaXCoDeR
    Posted 4 years ago #

    Well, here's the bug: http://core.trac.wordpress.org/ticket/13471

    It has been known for a month and not fixed yet.

  4. weepingtiger
    Posted 4 years ago #

    I have exactly this problem (using the Woothemes Canvas theme). I have tried using Lester Chans wp-page-navi plugin instead, but it makes no difference.


    When you choose Older Entries, the URL changes to show page 2, but the content is still page 1.

  5. mjepson
    Posted 4 years ago #

    @MaXCoDeR - I don't think that bug relates to this problem, as mine is ONLY in conjuction with using static page as home page. It works fine without that.

  6. nathanrice
    Posted 4 years ago #

    I don't know if this will work or not, but it's worth a shot. Try adding 'cat' => -0 to the query_posts args. See below:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    PS - sorry about the other stuff I changed. I'm anal like that.

  7. mjepson
    Posted 4 years ago #

    Make a page template in twentyten with this http://pastebin.com/St6h1ACV and setup that page as static front page and check pagenav

    It shows page 1 even when you are on page 2 :)

  8. nathanrice
    Posted 4 years ago #

    This seems to work (TwentyTen Blog Page Template):

    The key is to place the wp_reset_query(); call AFTER the posts navigation code, and making sure you pass the arguments to query_posts() correctly.

    query_posts( array( 'cat' => -0, 'paged'=> $paged ) );

    Just tested it on my local install and it's working fine.

  9. jlapitan
    Posted 4 years ago #

    @nathan i tried the one you suggested but its not working on woothemes canvas

  10. nathanrice
    Posted 4 years ago #

    I did that code for Magnus based on TwentyTen, as requested. I'm sure the same principles apply to Canvas, but they have to be implemented properly.

  11. mjepson
    Posted 4 years ago #

    Thanks for replying Nathan!

    I've tested your code, and still only get the first page to show. Used the code from your pastebin and added it to Blog page


    All the pages show the first page still.

  12. Spencer Finnell
    Posted 4 years ago #

    EDIT: Ah nevermind, didn't quite have it setup right. I can now confirm I have the same problem.

  13. nathanrice
    Posted 4 years ago #

    OK, I've narrowed down the problem. Whether or not this should be considered a bug, I'm not sure. Either way ...

    When the Blog page template is used on a normal page, the $wp_query->query_vars['paged'] variable gets set based on the page number we're viewing. So, assuming pagination works properly, you can navigate to /page/2/ and the ['paged'] variable gets set properly. (it's set to 0 on page 1, but that is expected behavior)

    However, when using a page with the Blog page template as a static homepage, no matter what you do, the ['paged'] variable stays as 0, no matter how you navigate. /page/2/ still returns 0 for the ['paged'] variable.

    However, there is a secondary variable in the query_args array that we can take advantage of, if ['paged'] isn't working. That variable is $wp_query->query_vars['page'] ... which I noticed after looking through the list of available query_args.

    So, with a little hacking and conditional logic, you CAN make this work. Here's how I did it:


    It's not ideal, but it works. I think the people who develop at WordPress would (perhaps justifiably) say that if you want to display blog posts on the front page, then you should probably use the index.php file for that, and delete the home.php file (or make it into a page template that can be used as a static homepage). Creating a Blog page template to display blog posts on the homepage seems like going around your ass to get to your elbow. There are just better ways to do it.

  14. mjepson
    Posted 4 years ago #

    Thanks for the help Nathan!

    Using the blog page template as homepage was just an example. Canvas for example has a magazine and business page template, that lots of users use as static homepage. Making them mess around in files seems a hard way of doing this, especially as this functionality has been working up to WP 3.0.

    I think this is a bug and it should be fixed :)

  15. egibney
    Posted 4 years ago #

    I have a very simple solution for this. Copy all of the code from the "Blog Template" page, then paste all of that content into the "index.php" page, remove the "Template Name: Blog" section at the top of the page. It should function on the front page now. As for making it work on subpages, not sure about that I'm afraid.

  16. tinmanjuggernaut
    Posted 4 years ago #

    @nathanrice thanks for your workaround! I think this is a bug as well.

    My desire it to simply have a static page (text/video) on my home page followed by the recent posts (formatted the same as the normal home page). I created a page template to do that. It works fine including proper pagination if the static page is not set to the front page. However if the front page is set to this static page, pagination stops working in the way nathan described - almost. My $paged variable is 0 on the home page and blank on page 2 (when echoed).

    My permalink structure is /%postname%/ . I've used Nathan's fix as a work around.

    @nathan, where did you find the $page variable? I didn't see it in the documentation. Is this a hack that might break on a future version?

  17. tinmanjuggernaut
    Posted 4 years ago #

    Hmmm, although the page loads properly now given the proper url (/page/2/, /page/3/, etc), the pagination links are not working. On /page/2/ I only get a Next link that is linking to /page/2/. Same on page 3.

    As before it works fine when this static page is not the front page. As soon as I set it to the front page this behavior manifests. If I specify 'global $paged;' before Nathan's if statement it fixes the pagination links.

  18. dxsmachina
    Posted 4 years ago #

    It's not just messing with blog post pagination.

    It also breaks pagination for new products at the bottom of my store that I created with the eShop plug-in. I'm not even using the blog part of wordpress for that, I'm just using static pages.

    I get a 404 if I click on the next page or the show all links. On all other pages the pagination works fine but not the static front page. Seems like a bug to me since the pagination was working perfectly right before I updated.

  19. mattkaner
    Posted 4 years ago #

    Hi there,

    Has anyone found a definitive solution to this? I'm using wp-pagenavi, and have tried to implement nathanrice's solution but it doesn't seem to work...

    Just to clarify - I'm using home.php to return a specific category of posts here

    but at the moment /?paged=2 (i'm not using permalinks for now) just doesn't do anything, returning the same results as before...

  20. mattkaner
    Posted 4 years ago #

    Found the solution

    It's the query_posts line I was using that caused it.

    Solution here if anyone else needs it:


  21. Christopher Anderton
    Posted 3 years ago #

    Thanks Nathan, query_posts( array( 'cat' => -0, 'paged'=> $paged ) ); was the answer for my problem using Paginator.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.