WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#9379 closed defect (bug) (duplicate)

Custom permalinks causes error when clicking Older Entries

Reported by: jsherk Owned by: ryan
Milestone: Priority: normal
Severity: minor Version: 2.7.1
Component: Permalinks Keywords:
Focuses: Cc:

Description

Using the default wordpress theme in 2.7.1, installed in www.mysite.com/wordpress/ .

Create a category (let's call it 'stuff'), and then add posts to that category (let's add 4 for now), and then set Reading-> Blog Pages Show At Most 3 Posts so that there will be more than one page.

Now set Permalinks to Custom: /%category%/%post_id%
so that they will show by Category name and post-id.

Now go to the category page
www.mysite.com/wordpress/stuff

You should see your first three posts, and Older Entries should also be highlighted. If you hover over Older Entries it will say
www.mysite.com/wordpress/stuff/page/2

But if you click on it, you will get either a "Sorry, nothing there" error, or a 404 error.

A possible solution is here:
http://barefootdevelopment.blogspot.com/2007/11/fix-for-wordpress-paging-problem.html

Change History (3)

comment:1 jsherk5 years ago

The barefootdevelopment solution did not work, but I was able to modify it and work around the problem:

When viewing pages from categories [permalink= /%category%/%post_id% and lets assume the category name is 'stuff' and I want to go to page 2], then $query_string is passed 'category_name'='stuff/page' and it is also passed 'p'='2'.

I had to remove the '/page' from the end of 'category_name', and I had to set 'paged'='2' and had to unset 'p'. Here is the workaround code plugin:

<?php
/*
Plugin Name: Fix Paging in Category Listings
Plugin URI:
Description: Fixes a bug where next/previous page links are broken in category listings
Version: 0.6
Author: Doug Smith (modified by Jeff Sherk)
Author URI:

Modified on March 23, 2009 by Jeff Sherk for WordPress 2.7.1

Based on original plugin info listed below:
Plugin Name: Fix Paging in Category Listings
Plugin URI: http://www.thinkbarefoot.com
Description: Fixes a bug where next/previous links are broken in category by year/month listings
Version: 0.5
Author: Doug Smith
Author URI: http://www.thinkbarefoot.com

Copyright 2007 Doug Smith (email: dsmith@…)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

*/

/

  • Function to fix problem where next/previous buttons are broken on list
  • of posts in a category when the custom permalink string is:
  • /%category%/%year%/%monthnum%/%postname%/
  • The problem is that with a url like this:
  • /category/2007/10/page/2
  • the 'page' looks like a post name, not the keyword "page"
  • MODIFIED ON March 23, 2009 by Jeff Sherk
  • Permalink structure was /%category%/%post_id% which looked like
  • www.mysite.com/wordpress/news/27
  • When attempting to go to another page, it looked like this
  • www.mysite.com/wordpress/news/27/page/2
  • but would generate a 404 error .
  • This modification takes $query_stringcategory_name? and chops the '/page'
  • off the end. It also takes $query_stringpaged? and sets it equal to
  • $query_stringp?, and then unsets $query_stringp?.
  • 'p' is not needed, but 'paged' is needed in order to make it work correctly */

function fix_page_in_category_from_query_string($query_string) {

Check to see if the 'p' and 'category_name' are set in $query_string
if ( isset($query_stringcategory_name?) && isset($query_stringp?) ) {

$category_name = $query_stringcategory_name?;
$category_len = strlen($category_name);

Check to see if the 'category_name' has '/page' on the end of it
if (substr($category_name, $category_len-5,5) == '/page') {

Remove '/page' from the end of 'category_name'
$query_stringcategory_name? = substr($query_stringcategory_name?,0,$category_len-5);

Set 'paged' equal to the page you want to go to
$query_stringpaged? = $query_stringp?;

Unset 'p' since we don't need it anymore because we set 'paged' instead
unset($query_stringp?);

}

}
return $query_string;

}

add_filter('request', 'fix_page_in_category_from_query_string');

?>

comment:2 Denis-de-Bernardy5 years ago

  • Component changed from General to Permalinks
  • Milestone changed from Unassigned to Future Release
  • Owner changed from anonymous to ryan
  • Priority changed from high to normal
  • Severity changed from major to minor

it's not recommended to use permalink structures that start with category or postname

comment:3 Denis-de-Bernardy5 years ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed

See #8905

Note: See TracTickets for help on using tickets.