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

Query Pagination: add an empty wrapper when at first/last page #35430

Closed
wants to merge 2 commits into from

Conversation

MaggieCabrera
Copy link
Contributor

@MaggieCabrera MaggieCabrera commented Oct 7, 2021

Description

Fixes #34997

To keep the alignments consistent between pages and between the editor and the frontend, I've added an empty wrapper (right now it's a simple span to test the fix, I can add the rest of the wrapper attributes and/or change it to an anchor depending on discussion).

How has this been tested?

I've used the following markup on emptytheme, tested with inherit set to true and false:

<!-- wp:query {"queryId":13,"query":{"perPage":"5","pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false},"displayLayout":{"type":"list"}} -->
<div class="wp-block-query"><!-- wp:post-template -->
<!-- wp:post-title {"isLink":true} /-->

<!-- wp:post-excerpt /-->
<!-- /wp:post-template -->

<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"space-between"}} -->
<!-- wp:query-pagination-previous /-->

<!-- wp:query-pagination-numbers /-->

<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination --></div>
<!-- /wp:query -->

Adapt your site or your query block so the pagination shows up and navigate to the first and last pages of the loop. The numbers should stay in the center.

Screenshots

Editor:

Screenshot 2021-10-07 at 14 00 34

First page:

Before After
Screenshot 2021-10-07 at 13 58 45 Screenshot 2021-10-07 at 13 58 56

Last page:

Before After
Screenshot 2021-10-07 at 13 58 39 Screenshot 2021-10-07 at 13 59 02

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@MaggieCabrera MaggieCabrera self-assigned this Oct 7, 2021
@MaggieCabrera MaggieCabrera added the [Block] Query Pagination Affects the Query Pagination Block - used for pagination within the Query Loop Block label Oct 7, 2021
@MaggieCabrera
Copy link
Contributor Author

It could be interesting to keep the label as a disabled element so that it maintains its size and keeps the numbers centered and always in the same position regardless of the page you are in.

@MaggieCabrera
Copy link
Contributor Author

MaggieCabrera commented Oct 15, 2021

The empty div was moving the numbers between pages, so I went with placeholders for the text and added classes for the first/last pages in case the theme devs want to hide these. We could add visibility:hidden to these or lower the opacity. I'd love to hear any input on this approach.

Before:

Screen Capture on 2021-10-15 at 12-22-25

After:

Screen Capture on 2021-10-15 at 12-35-05

Above is TT2

@MaggieCabrera MaggieCabrera marked this pull request as ready for review October 15, 2021 10:38
@carolinan
Copy link
Contributor

My test installation has 4 posts.

When I apply the PR and enable Empty theme, Twenty Twenty-Two or Blockbase I see the following on the front:
Notice: Undefined variable: wp_query in blocks/query-pagination-next.php on line 30 Notice: Trying to get property 'max_num_pages' of non-object in blocks/query-pagination-next.php on line 30

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query Pagination: Control the layout when next/previous buttons are not displayed
2 participants