Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/block-library/src/categories/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"default": true
}
},
"usesContext": [ "enhancedPagination" ],
"supports": {
"align": true,
"html": false,
Expand Down
15 changes: 13 additions & 2 deletions packages/block-library/src/categories/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
* Renders the `core/categories` block on server.
*
* @since 5.0.0
* @since 6.7.0 Enable client-side rendering if enhancedPagination context is true.
*
* @param array $attributes The block attributes.
* @param array $attributes The block attributes.
* @param string $content Block default content.
* @param WP_Block $block Block instance.
*
* @return string Returns the categories list/dropdown markup.
*/
function render_block_core_categories( $attributes ) {
function render_block_core_categories( $attributes, $content, $block ) {
static $block_id = 0;
++$block_id;

Expand Down Expand Up @@ -54,6 +57,14 @@ function render_block_core_categories( $attributes ) {
$wrapper_markup = '<ul %1$s>%2$s</ul>';
$items_markup = wp_list_categories( $args );
$type = 'list';

if ( ! empty( $block->context['enhancedPagination'] ) ) {
$p = new WP_HTML_Tag_Processor( $items_markup );
while ( $p->next_tag( 'a' ) ) {
$p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
}
$items_markup = $p->get_updated_html();
}
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => "wp-block-categories-{$type}" ) );
Expand Down