-
Notifications
You must be signed in to change notification settings - Fork 59
fix(categories): fix pager urls #2913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
On a permalink structure like this /%category%/%postname%/ some fixes to the pager was needed. Also guard against a post with the slug 'page' to avoid confusion to routing.
Don't hardcode category base
leogermani
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works well and fixes the issue! I left two comments
includes/class-category-pager.php
Outdated
| * Action callback for init. | ||
| */ | ||
| public static function on_init() { | ||
| if ( '/%category%/%postname%/' === get_option( 'permalink_structure' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've ran some tests and the issue also occurs with other settings, for example /%category%/%post_id%/.
It does not happen if you do /%post_id%//%category% though.
Didn't go too far to get at the bottom of why this happens, but I think we can assume that it happens if the permalink structure starts with category?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I changed it to sniff if the permalink structure starts with /%category%/.
includes/class-category-pager.php
Outdated
| /** | ||
| * Action callback for init. | ||
| */ | ||
| public static function on_init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT of hooking directly into paginate_links and checking the permalink_structure option there?
I think it's better to have that check done only when really needed than on every single request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes much better sense. I changed it. Thanks
* PR feedback adressed * Use 'category' as default if base is empty
|
This is ready for re-review. I also caught that the |
|
(merged in |
|
I think this is good to go. @naxoc do you want to turn this into a hotfix so we can release it immediately? Or can it wait the regular release flow? If you want to make it a hotfix, we need to rebase it against the release branch, and prefix the branch name with |
* fix(categories): fix pager urls On a permalink structure like this /%category%/%postname%/ some fixes to the pager was needed. Also guard against a post with the slug 'page' to avoid confusion to routing. * fix(categories): fix pager urls Don't hardcode category base * Don't hardcode category base and remove unneeded filter * fix(categories): fix pager urls * PR feedback adressed * Use 'category' as default if base is empty --------- Co-authored-by: Adam Boro <aborowski24@gmail.com>
# [3.1.0-alpha.2](v3.1.0-alpha.1...v3.1.0-alpha.2) (2024-02-09) ### Bug Fixes * **categories:** fix pager urls ([#2913](#2913)) ([bb7e534](bb7e534))
|
🎉 This PR is included in version 3.1.0-alpha.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 3.1.0-epic-ras-acc.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [3.1.0](v3.0.5...v3.1.0) (2024-02-20) ### Bug Fixes * add frequency tab options for donations, even when tiers are disabled ([#2930](#2930)) ([cb7eb7b](cb7eb7b)) * **categories:** fix pager urls ([#2913](#2913)) ([bb7e534](bb7e534)) * **categories:** fix pager urls ([#2913](#2913)) ([c851bb6](c851bb6)) * **engagement-wizard:** handle error when retrieving subscription lists ([e85c108](e85c108)) * **ras:** only sync spend total and last payment amounts for completed orders ([#2886](#2886)) ([68aaf39](68aaf39)) * redirect to origin from magic link ([9f41947](9f41947)) * typescript errors ([dc27973](dc27973)) * TypeScript usage; add to CI ([#2884](#2884)) ([6f5e7a6](6f5e7a6)) * update newsletter scroll appearance in Sign Up modal ([#2897](#2897)) ([496723a](496723a)) * update path to wide template file ([#2918](#2918)) ([fdd6b69](fdd6b69)) ### Features * **ci:** add epic/* release workflow and rename `master` to `trunk` ([#2895](#2895)) ([ea02075](ea02075)), closes [#2897](#2897) [#2886](#2886) * **reader-revenue:** make NYP and Stripe Gateway optional ([#2866](#2866)) ([fcfa88c](fcfa88c)) * remove new tab default on image credits ([#2880](#2880)) ([3c996b1](3c996b1)) * **wc:** override cart, checkout, and my-account page templates ([#2893](#2893)) ([68b1836](68b1836))
|
🎉 This PR is included in version 3.1.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
Because WP allows a url that shouldn't really exist when a site has the
/%category%/%postname%/ permalink structure, the pager links break. See https://core.trac.wordpress.org/ticket/8905 and https://core.trac.wordpress.org/ticket/21209This PR tries to help out the pager only on sites with that specific url structure.
How to test the changes in this Pull Request:
Before applying the patch:
/%category%/%postname%kitten./kitten/page/2and the page 404s.Now apply the patch
/kitten