Skip to content

Fix: Pagination misalignment on first and last pages in Query Pagination Block#70607

Open
coderGtm wants to merge 1 commit intoWordPress:trunkfrom
coderGtm:fix/pagination-misalignment
Open

Fix: Pagination misalignment on first and last pages in Query Pagination Block#70607
coderGtm wants to merge 1 commit intoWordPress:trunkfrom
coderGtm:fix/pagination-misalignment

Conversation

@coderGtm
Copy link
Copy Markdown
Contributor

@coderGtm coderGtm commented Jul 3, 2025

What?

Closes #69580

When pagination is set to “space between,” it displays correctly on middle pages with three elements: page numbers centered, and navigation controls on either side. However, on the first and last category pages, the third element (either the previous or next control) is missing. This causes the page numbers to shift to the edge instead of remaining centered, disrupting the consistent layout.

This PR fixes that issue by keeping the page numbers centered even on first and last pages.

Why?

This ensures consistent and expected UX for users as the sudden drastic shift in position of the page numbers while on first and last pages can be quite confusing to the users.

How?

A few approaches were discussed in the linked issue but each had their gotchas. Initially I was going to solve it using one of the approaches (rendering empty element) but that would have caused problem in future if border styling is introduced. Somehow while inspecting the styles of the elements, I came up with this solution to conditionally apply margin to the page numbers using only CSS.

So basically, I wrote the CSS selectors for when there will be no previous/next buttons and accordingly applied auto inline-margin in the corresponding directions.

Testing Instructions

  1. Go to Pages > Add New.
  2. Add a Query Loop block.
  3. Configure it to display a list of posts.
  4. Ensure that the Pagination block is present.
  5. Set the justification of the Pagination block to Space between items.
  6. Add Enough Posts for Multiple Pages: Ensure the post count exceeds the Posts per Page value to trigger pagination.
  7. Check First and Last Pages: - Navigate to the first and last pages of the query loop.
  8. Observe that page numbers do not shift to the edges due to the missing previous or next control.

Screenshots or screencast

screencast.mp4
Page Before After
First Page Screenshot 2025-07-03 at 8 30 06 PM Screenshot 2025-07-03 at 8 30 22 PM
Last Page Screenshot 2025-07-03 at 8 30 42 PM Screenshot 2025-07-03 at 8 31 04 PM

@coderGtm coderGtm marked this pull request as ready for review July 3, 2025 15:48
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 3, 2025

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core, Gutenberg Plugin.
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 3, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: coderGtm <gautam23@git.wordpress.org>
Co-authored-by: yyppsk <pranjalpratapsingh@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: n2erjo00 <n2erjo00@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: gigitux <gigitux@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Block] Query Pagination Affects the Query Pagination Block - used for pagination within the Query Loop Block labels Jul 4, 2025
@coderGtm
Copy link
Copy Markdown
Contributor Author

coderGtm commented Jul 4, 2025

Hi @t-hamano

Based on our discussion in #69580, I decided to work on this issue, but as explained, took a different approach to avoid any possible gotchas. What do you think about it?

@yyppsk
Copy link
Copy Markdown

yyppsk commented Jul 9, 2025

Hey @coderGtm,

I have tested this PR. It correctly resolves the issue with pagination layout when using the "space between" setting. The pagination block now maintains a consistent layout across all pages, ensuring the page numbers remain centered even on the first and last pages.

Environment: WordPress Block Editor (Gutenberg)
Machine: macOS Air (M3)
Browsers Tested: Chrome, Safari, Firefox


Scope of Change

  • Fixes the misalignment of pagination elements on first and last pages when "space between" justification is used.
  • Prevents page numbers from shifting to the left or right edge when the previous or next navigation control is missing.
  • Uses a CSS-only solution that conditionally applies inline margins to maintain alignment, avoiding potential future styling issues.

Steps to Reproduce

  1. Navigate to Pages > Add New.
  2. Insert a Query Loop block and configure it to display a list of posts.
  3. Confirm that the Pagination block is present within the loop.
  4. Set the Pagination block's justification to Space between items.
  5. Ensure there are enough posts to span multiple pages (more than the "Posts per Page" value).
  6. Navigate through the pagination to the first and last pages of the loop.

Expected Results

  • On middle pages, the pagination should display:
    • Navigation controls on both sides (Previous and Next).
    • Page numbers centered between them.
  • On the first page:
    • "Previous" control is absent.
    • Page numbers remain centered; do not shift left.
  • On the last page:
    • "Next" control is absent.
    • Page numbers remain centered; do not shift right.

Actual Results

  • The pagination layout behaves consistently across all pages.
  • Page numbers stay centered whether one or both navigation controls are present.
  • The CSS-only solution performs reliably without layout or spacing issues.
  • Verified across Chrome, Safari, and Firefox with consistent rendering.

Before and After Summary

Scenario Before (Issue) After (Fixed Behavior)
First Page Page numbers aligned to left Page numbers centered
Last Page Page numbers aligned to right Page numbers centered
Middle Pages Layout correct (controls + centered numbers) Layout remains correct

Comparison

Before Fix

Layout keeps shifting for the numbering for first and last page.

Screenshot 2025-07-09 at 3 24 01 PM Screenshot 2025-07-09 at 3 24 12 PM Screenshot 2025-07-09 at 3 24 24 PM

After Fix

Layout is consistent for the numbering for first and last page.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Query Pagination Affects the Query Pagination Block - used for pagination within the Query Loop Block [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query Pagination block: Pagination misalignment on first and last pages

3 participants