WordPress bad next_posts_link when using a static front page and custom permalink structure

Sunday, March 1st, 2009

Wordpress allows setting a static page to be the main page, then another page can be assigned as the blog posts page.

This is under Settings | Reading. The option is called “Front page displays.” Choose “A static page” then select a page to be the “Front page” and a page to be the “Posts page.”

For example, a page called “Welcome” could be set as the “Front page” and a page called “Blog” could be set as the “Posts page.” Users would always get the Welcome page when they visit the main URL at yourblog.com/ and would see the blog posts when they went to yourblog.com/blog.

In this kind of configuration it’s common to set the Permalinks to match the “Posts page” blog URL. Under Settings | Permalinks, choose a Custom Structure and set it to /blog/%postname%.

Now the URLs will look like this:

  • Main URL (showing Welcome page): yourblog.com/
  • Blog URL (showing the blog itself): yourblog.com/blog
  • Blog posts (showing one post): yourblog.com/blog/name-of-a-post

This is all nice and clean, right?

But there’s a bug! If you click on “Older entries” to go to yourblog.com/blog/page/2, you’ll get a 404 Not Found error!

The solution is to go into your wp-includes/rewrite.php file and make a change.

For WordPress 2.7.1 look for this section:


if ( 0 === strpos($structure, '%postname%') ||
0 === strpos($structure, '%category%') ||
0 === strpos($structure, '%tag%') ||
0 === strpos($structure, '%author%') )
$this->use_verbose_page_rules = true;
else
$this->use_verbose_page_rules = false;

And change it to:


if ( 0 === strpos($structure, '%postname%') ||
0 === strpos($structure, '%category%') ||
0 === strpos($structure, '%tag%') ||
0 === strpos($structure, '%author%') )
$this->use_verbose_page_rules = true;
else
$this->use_verbose_page_rules = true;

Then go to Settings | Permalinks and save your configuration again.

The links to older entries should work now.

Here’s the link to the WordPress bug: bad next_posts_link when using a Static Front Page and custom permalink structure