From 3255e102b12488d70acb84ef7ee99227628edc61 Mon Sep 17 00:00:00 2001 From: David Arenas Date: Wed, 24 Jan 2024 14:38:12 +0100 Subject: [PATCH 1/2] Add `data-wp-key` to pagination numbers --- .../src/query-pagination-numbers/index.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/block-library/src/query-pagination-numbers/index.php b/packages/block-library/src/query-pagination-numbers/index.php index 2f9370751f6d2..218717b930e74 100644 --- a/packages/block-library/src/query-pagination-numbers/index.php +++ b/packages/block-library/src/query-pagination-numbers/index.php @@ -91,14 +91,19 @@ function render_block_core_query_pagination_numbers( $attributes, $content, $blo } if ( $enhanced_pagination ) { - $p = new WP_HTML_Tag_Processor( $content ); + $p = new WP_HTML_Tag_Processor( $content ); + $dots_i = 0; while ( $p->next_tag( - array( - 'tag_name' => 'a', - 'class_name' => 'page-numbers', - ) + array( 'class_name' => 'page-numbers' ) ) ) { - $p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' ); + if ( 'A' === $p->get_tag() ) { + $p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' ); + $p->set_attribute( 'data-wp-key', $p->get_attribute( 'href' ) ); + } elseif ( $p->has_class( 'current' ) ) { + $p->set_attribute( 'data-wp-key', 'current' ); + } elseif ( $p->has_class( 'dots' ) ) { + $p->set_attribute( 'data-wp-key', 'dots-' . $dots_i++ ); + } } $content = $p->get_updated_html(); } From f61a275613caea1b2d0f41a752272f4345814095 Mon Sep 17 00:00:00 2001 From: David Arenas Date: Mon, 12 Feb 2024 15:01:33 +0100 Subject: [PATCH 2/2] Use tag index as the `data-wp-key` value --- .../src/query-pagination-numbers/index.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/block-library/src/query-pagination-numbers/index.php b/packages/block-library/src/query-pagination-numbers/index.php index 218717b930e74..e6f8b46111040 100644 --- a/packages/block-library/src/query-pagination-numbers/index.php +++ b/packages/block-library/src/query-pagination-numbers/index.php @@ -91,18 +91,16 @@ function render_block_core_query_pagination_numbers( $attributes, $content, $blo } if ( $enhanced_pagination ) { - $p = new WP_HTML_Tag_Processor( $content ); - $dots_i = 0; + $p = new WP_HTML_Tag_Processor( $content ); + $tag_index = 0; while ( $p->next_tag( array( 'class_name' => 'page-numbers' ) ) ) { + if ( null === $p->get_attribute( 'data-wp-key' ) ) { + $p->set_attribute( 'data-wp-key', 'index-' . $tag_index++ ); + } if ( 'A' === $p->get_tag() ) { $p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' ); - $p->set_attribute( 'data-wp-key', $p->get_attribute( 'href' ) ); - } elseif ( $p->has_class( 'current' ) ) { - $p->set_attribute( 'data-wp-key', 'current' ); - } elseif ( $p->has_class( 'dots' ) ) { - $p->set_attribute( 'data-wp-key', 'dots-' . $dots_i++ ); } } $content = $p->get_updated_html();