Make WordPress Core

Opened 17 years ago

Last modified 3 months ago

#8905 assigned defect (bug)

Category pagination broken with certain permalink structures

Reported by: rmccue's profile rmccue Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.7
Component: Permalinks Keywords: needs-patch needs-testing 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 (18)

#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
16 years ago

  • Milestone changed from Future Release to 2.9

#4 @jsherk
16 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
13 years ago

Related: #21209

Last edited 13 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
11 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
6 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
3 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. 😃

Note: See TracTickets for help on using tickets.