Make WordPress Core

Opened 17 years ago

Closed 2 months ago

Last modified 8 weeks ago

#8905 closed defect (bug) (worksforme)

Category pagination broken with certain permalink structures

Reported by: rmccue's profile rmccue Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.7
Component: Permalinks Keywords: close
Focuses: Cc:

Description

If one uses a permalink structure with %category% followed by %postname%, accessing pagination can cause a 404, as WordPress attempts to look for a post called "page".

As per http://barefootdevelopment.blogspot.com/2007/11/fix-for-wordpress-paging-problem.html

Presumably can occur with other permalink structures too.

Change History (20)

#1 @Denis-de-Bernardy
17 years ago

  • Keywords needs-patch added

#2 @Denis-de-Bernardy
17 years ago

  • Milestone changed from 2.8 to Future Release

punting

#3 @Denis-de-Bernardy
17 years ago

  • Milestone changed from Future Release to 2.9

#4 @jsherk
17 years ago

  • Cc jsherk added

I proposed a possible solution here in #9379

#5 @emartin24
16 years ago

Ran into this issue today - would love to see a fix.

I'm not sure if it is as simple as putting some extra logic in parse_request()? Using Doug Smith's code as inspiration, I added the following right before $this->query_vars = apply_filters('request', $this->query_vars); :

if ($this->query_vars['name'] === 'page' && isset($this->query_vars['page'])) {
	unset($this->query_vars['name']);
	$this->query_vars['paged'] = str_replace('/', '', $this->query_vars['page']);
}

Thoughts?

#6 @azaozz
16 years ago

  • Milestone changed from 2.9 to Future Release

No patch.

#7 @SergeyBiryukov
14 years ago

Related: #21209

Last edited 14 years ago by SergeyBiryukov (previous) (diff)

#8 @wonderboymusic
13 years ago

  • Keywords needs-patch removed
  • Milestone Future Release deleted
  • Resolution set to worksforme
  • Status changed from new to closed

http://wordpress-core/uncategorized/test-post-goes-here-this-is-some-more/2/ totally works for me when using <!--nextpage--> and navigating to page 2

#9 @rmccue
13 years ago

Pretty sure this was fixed when some of the permalink stuff was redone.

#10 @SergeyBiryukov
13 years ago

  • Keywords needs-patch added
  • Milestone set to Future Release
  • Resolution worksforme deleted
  • Status changed from closed to reopened

This ticket is about category pagination, not single post pagination.

As noted in #21209, the issue still can be reproduced with bare category slugs:

  1. Set permalink structure to /%category%/%postname%/.
  2. http://mysite/mycat/page/2 gives a 404 error.

Debug Bar info:

Request: mycat/page/2
Query String: page=%2F2&name=page&category_name=mycat
Matched Rewrite Rule: (.+?)/([^/]+)(/[0-9]+)?/?$
Matched Rewrite Query: category_name=mycat&name=page&page=%2F2

#11 @SergeyBiryukov
13 years ago

#23111 was marked as a duplicate.

#12 @ryan
12 years ago

  • Owner ryan deleted
  • Status changed from reopened to assigned

#13 @loushou
11 years ago

This is already fixed. Unless there is some new issue that is not clear here, then this should probably be closed. @SergeyBiryukov's reproduction steps produce the second page now, not a 404. It's not my place to close this, but I'm pretty sure it can be closed as resolved.

#14 @chriscct7
10 years ago

  • Keywords needs-testing close added

#15 @swissspidy
9 years ago

  • Keywords close removed

When there's a post with the slug page, http://mysite/mycat/page/2 shows that post. If there's none, I get a 404.

#16 @SergeyBiryukov
7 years ago

#46475 was marked as a duplicate.

#17 @zeshanb
5 years ago

Hi there,

Paginate_links function inside page template works fine. I can display a category with pagination using a page template pagetemplate-categoryname.php but not a category-categoryname.php, or even the root category.php template in a theme.

For slug page mentioned above the paginate_links would look like this:

<?php
					echo paginate_links( array(
						'format' => 'page/%#%',
						'current' => max( 1, get_query_var('paged') ),
						'total' => $wp_query->max_num_pages,
						'prev_next'    => True,
						'prev_text'    => __("<i class=\"material-icons\">chevron_left</i>"),
						'next_text'    => __("<i class=\"material-icons\">chevron_right</i>"),
						'type' => 'list',
					));
				?>

There is a "category pagination fix" plugin being offered for category pagination when this should be part of core features of a content management system:

https://wordpress.org/support/plugin/category-pagination-fix/reviews/

Thank you for your time.

Regards,

Zeshan

Last edited 5 years ago by zeshanb (previous) (diff)

#18 @callumbw95
7 months ago

  • Keywords close added

Hi All,

I have just tested this on my local set up running the trunk branch, and this appears to be working as it should be now.

Test Report

Description

Testing an issue with pagination with the following permalink structure: /%category%/%postname%.

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.4.7
  • Server: nginx/1.27.5
  • Database: mysqli (Server: 8.0.40 / Client: mysqlnd 8.4.7)
  • Browser: Chrome 137.0.0.0
  • OS: macOS
  • Theme: Twenty Seventeen 3.9
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Steps to Reproduce when there are posts within a category.

  1. Change permalink structure on the site to: /%category%/%postname%
  2. Navigate to a category with enough posts to require pagination.
  3. Using the page navigation links, go to any page beyond the first one.
  4. ✅ The page loads and the additional page of posts displays.

Steps to Reproduce when there are not any posts within a category .

  1. Change permalink structure on the site to: /%category%/%postname%
  2. Navigate to a category with zero posts.
  3. ✅ The Page displays a 404, which is identical to the other permalink structures I have tested with.

I believe this issue has now resolved over the years, and we are safe to close this ticket down? As of such I have attached the close tag. 😃

#19 @juanmaguitar
2 months ago

  • Keywords needs-patch needs-testing removed
  • Resolution set to worksforme
  • Status changed from assigned to closed

Bug Report

Description

Testing an issue with pagination with the following permalink structure: /%category%/%postname%.
The conclusion is that the bug cannot be reproduced.

Environment

  • WordPress: 6.9
  • PHP: 8.0.30
  • Server: PHP.wasm
  • Database: WP_SQLite_Driver (Server: 8.0.38 / Client: 3.51.0)
  • Browser: Chrome 143.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.4
  • MU Plugins: None activated
  • Plugins: Hello Dolly

Steps to Reproduce to setup the test environment

Open this playground link that will open a WP site and the browser and:

  • Set up WordPress with PHP 8.3
  • Configure permalinks to /%category%/%postname%/
  • Create Sports and Music categories
  • Generate 25 posts alternating between the two categories
  • Log you in as admin (username: admin, password: password)

The blueprint loaded in the Playground link is this one:

{
  "$schema": "https://playground.wordpress.net/blueprint-schema.json",
  "landingPage": "/",
  "preferredVersions": {
    "php": "8.3",
    "wp": "latest"
  },
  "steps": [
    {
      "step": "login",
      "username": "admin",
      "password": "password"
    },
    {
      "step": "setSiteOptions",
      "options": {
        "permalink_structure": "/%category%/%postname%/"
      }
    },
    {
      "step": "runWpInstallationWizard",
      "options": {
        "adminUsername": "admin",
        "adminPassword": "password"
      }
    },
    {
      "step": "wp-cli",
      "command": "wp term create category Sports --porcelain"
    },
    {
      "step": "wp-cli",
      "command": "wp term create category Music --porcelain"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='The Future of Professional Basketball' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Top 10 Rock Albums of the Decade' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Olympic Games Highlight Reel' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Jazz Legends: A Retrospective' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Soccer World Cup Preview' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Electronic Music Festival Guide' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Tennis Champions Crowned' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Classical Music for Beginners' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Baseball Season Recap' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Hip Hop Evolution Documentary' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Marathon Running Tips' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Indie Music Scene Report' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Swimming Competition Results' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Country Music Awards Recap' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Golf Tournament Championship' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Pop Music Trends Analysis' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Hockey League Standings' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Blues Music History' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Cycling Race Coverage' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Latin Music Rising Stars' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Rugby Match Highlights' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Reggae Music Festival Review' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Boxing Championship Fight' --post_status=publish --post_category=sports"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Folk Music Traditions' --post_status=publish --post_category=music"
    },
    {
      "step": "wp-cli",
      "command": "wp post create --post_title='Volleyball Tournament Finals' --post_status=publish --post_category=sports"
    }
  ]
}

  • Navigate to the Sports category /category/sports/
  • Using the page navigation links, go to any page beyond the first one.

Expected Results

  1. ✅ The page loads (/category/sports/page/2/) and the additional page of posts displays.

Actual Results

  1. ✅ The page loads (/category/sports/page/2/) and the additional page of posts displays.

Additional Noteschat

Debug bar info

Request: category/sports/page/2
Query String: paged=2&category_name=sports
Matched Rewrite Rule: category/(.+?)/page/?([0-9]{1,})/?$
Matched Rewrite Query: category_name=sports&paged=2
Last edited 8 weeks ago by juanmaguitar (previous) (diff)

#20 @sabernhardt
2 months ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.