Skip to content
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

Add option to paginate_links to apply format on all pages #1540

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ntsekouras
Copy link

Trac ticket: https://core.trac.wordpress.org/ticket/53868

paginate_links doesn't use the provided format when the page is 1. This is great for the main query as it removes the extra query params making the URL shorter, but in the case of custom queries is problematic.

If no additional data is appended via. add args / add fragment, the string remains empty at the time of output, which browsers then default it to the current page URL.

The code for this behavior is this: $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );

My proposed solution is to add a new format_all_pages option in paginate_links that would enforce applying the format for all pages, including the first one. I could use some input for a better name for this option 😄 .

Notes

In order to test this properly you have to enable pretty permalinks. If not the url will have the page_id param and therefore the final url will not be empty.

Testing instructions

To reproduce:

  1. Create a couple of posts - no content is needed
  2. Create a page and insert Query Loop block, set the Items per Page to 1 and make sure the inherit is false. After that insert a Query Pagination block inside Query Loop.
  3. Save and in front-end navigate to the second page of the query.
  4. Observe that the link for the first page is pointing to the current url.

To test the solution:

  1. You can test by editing this line in Query Pagination Numbers:https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/blocks/query-pagination-numbers.php#L46 and add the new option: format_all_pages = true. (Noting that this will need a follow up in GB to update the block functionality.
  2. Observe that after navigating to the second page, the first page's link is correct and is not the current url.

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

* @type bool $prev_text The previous page text. Default '« Previous'.
* @type bool $next_text The next page text. Default 'Next »'.
* @type string $prev_text The previous page text. Default '« Previous'.
* @type string $next_text The next page text. Default 'Next »'.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are unrelated, but noticed the wrong type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant