Support » Fixing WordPress » WP 3.0 bug with pagination? (when using static page as homepage)

  • Hey,

    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:

    http://cl.ly/ebffedf37b7a3c5d709b

    It shows only the page title of that page:

    http://cl.ly/8a3addadd9defe9dbce2

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

    http://cl.ly/9eff8e3a1ec33a5b9f51

    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

Viewing 15 replies - 1 through 15 (of 20 total)
  • 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.

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

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

    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.

    http://www.thefleetmanager.co.uk

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

    Thread Starter mjepson

    (@mjepson)

    @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.

    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.

    Thread Starter mjepson

    (@mjepson)

    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 🙂

    This seems to work (TwentyTen Blog Page Template):
    http://pastebin.com/u0M0vAWU

    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.

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

    @jlapitan
    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.

    Thread Starter mjepson

    (@mjepson)

    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

    http://cl.ly/a98cbe6240a4d1f5ffdb

    All the pages show the first page still.

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

    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:

    http://pastebin.com/brK4AM51

    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.

    Thread Starter mjepson

    (@mjepson)

    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 🙂

    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.

    @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?

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘WP 3.0 bug with pagination? (when using static page as homepage)’ is closed to new replies.