Open scruffian opened 2 years ago
I have come across this pagination problem in WP 5.9 (so core rather than Gutenberg plugin?).
My set-up is:
If I choose code reuse over minimising nesting, I put my pagination block in a template part. This results in links such as <a class="page-numbers" href="?query-page=2">2</a>
. These links do not work: the page numbers are updated, but the page content (i.e. the query result) is not.
<!-- wp:query -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:template-part {"slug":"article-loop","tagName":"article"} /-->
<!-- /wp:post-template -->
<!-- wp:template-part {"slug":"navigation-loop","tagName":"div"} /-->
</div>
<!-- /wp:query -->
<!-- wp:query-pagination -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->
<!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-excerpt /-->
<div class="wp-block-template-part">
<div class="wp-container-62273d09eff1f wp-block-query-pagination">
<div class="wp-block-query-pagination-numbers">
<span aria-current="page" class="page-numbers current">1</span>
<a class="page-numbers" href="?query-page=2">2</a>
<a class="page-numbers" href="?query-page=3">3</a>
<span class="page-numbers dots">…</span>
<a class="page-numbers" href="?query-page=7">7</a>
</div>
<a href="/wordpress/?query-page=2" class="wp-block-query-pagination-next">Next Page</a>
</div>
</div>
These links don't work.
Notice that:
?query-page=2
), whereas the next and previous (latter not shown) page links include the WP directory (/wordpress/?query-page=2
)If I choose minimising nesting over code reuse, I put the pagination block in a template. This results in such links as <a class="page-numbers" href="http://localhost/wordpress/page/2/">2</a>
. These links work as expected.
<!-- wp:query -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:template-part {"slug":"article-loop","tagName":"article"} /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->
</div>
<!-- /wp:query -->
<!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-excerpt /-->
<div class="wp-container-62273d09f03ff wp-block-query-pagination">
<div class="wp-block-query-pagination-numbers">
<span aria-current="page" class="page-numbers current">1</span>
<a class="page-numbers" href="http://localhost/wordpress/page/2/">2</a>
<a class="page-numbers" href="http://localhost/wordpress/page/3/">3</a>
<span class="page-numbers dots">…</span>
<a class="page-numbers" href="http://localhost/wordpress/page/7/">7</a></div>
<a href="http://localhost/wordpress/page/2/" class="wp-block-query-pagination-next">Next Page</a>
</div>
</div>
These links do work.
Notice that:
http://localhost/wordpress/page/2/
)I bumped into this too. The issue seems to be that, when in a template part or in a pattern, the pagination doesn't inherit the query context. Basically the condition below is never met, while it should https://github.com/WordPress/gutenberg/blob/d06ee3a4c5d18e336e2a7f3e78dcf6a7f9a6e397/packages/block-library/src/query-pagination-next/index.php#L33
Adding for now to the phase 2 board as this is the closest issue I could find related to the following feedback pulled from https://github.com/WordPress/gutenberg/issues/48443
It's frustrating to use the “query pagination” block and not being able to drag it around to reposition. It seems to only want to exist as a direct child of Query Loop. Contrast to the “prev” and “next” post block which are much easier to use, insert, copy, move.
Description
When the query pagination block is inside a template block it doesn't go to the next page anymore.
Step-by-step reproduction instructions
To reproduce, use this PR: https://github.com/WordPress/theme-experiments/pull/302
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes