Skip to content

Commit

Permalink
Pagination Numbers: Add data-wp-key to pagination numbers if enhanc…
Browse files Browse the repository at this point in the history
…ed pagination is enabled (#58189)

* Add `data-wp-key` to pagination numbers

* Use tag index as the `data-wp-key` value

Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
Co-authored-by: c4rl0sbr4v0 <cbravobernal@git.wordpress.org>
  • Loading branch information
4 people authored and youknowriad committed Feb 13, 2024
1 parent d1155e0 commit f7e9fdf
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/block-library/src/query-pagination-numbers/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@ 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 );
$tag_index = 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 ( 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' );
}
}
$content = $p->get_updated_html();
}
Expand Down

0 comments on commit f7e9fdf

Please sign in to comment.