Changeset 59072 for trunk/src/wp-includes/blocks/categories.php
- Timestamp:
- 09/20/2024 01:53:52 AM (15 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/blocks/categories.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/categories.php
r58187 r59072 10 10 * 11 11 * @since 5.0.0 12 * @since 6.7.0 Enable client-side rendering if enhancedPagination context is true. 12 13 * 13 * @param array $attributes The block attributes. 14 * @param array $attributes The block attributes. 15 * @param string $content Block default content. 16 * @param WP_Block $block Block instance. 14 17 * 15 18 * @return string Returns the categories list/dropdown markup. 16 19 */ 17 function render_block_core_categories( $attributes ) {20 function render_block_core_categories( $attributes, $content, $block ) { 18 21 static $block_id = 0; 19 22 ++$block_id; 23 24 $taxonomy = get_taxonomy( $attributes['taxonomy'] ); 20 25 21 26 $args = array( … … 24 29 'orderby' => 'name', 25 30 'show_count' => ! empty( $attributes['showPostCounts'] ), 31 'taxonomy' => $attributes['taxonomy'], 26 32 'title_li' => '', 27 33 'hide_empty' => empty( $attributes['showEmpty'] ), … … 34 40 $id = 'wp-block-categories-' . $block_id; 35 41 $args['id'] = $id; 36 $args['show_option_none'] = __( 'Select Category' ); 37 $wrapper_markup = '<div %1$s><label class="screen-reader-text" for="' . esc_attr( $id ) . '">' . __( 'Categories' ) . '</label>%2$s</div>'; 38 $items_markup = wp_dropdown_categories( $args ); 39 $type = 'dropdown'; 42 $args['name'] = $taxonomy->query_var; 43 $args['value_field'] = 'slug'; 44 $args['show_option_none'] = sprintf( 45 /* translators: %s: taxonomy's singular name */ 46 __( 'Select %s' ), 47 $taxonomy->labels->singular_name 48 ); 49 50 $show_label = empty( $attributes['showLabel'] ) ? ' screen-reader-text' : ''; 51 $default_label = $taxonomy->label; 52 $label_text = ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label; 53 $wrapper_markup = '<div %1$s><label class="wp-block-categories__label' . $show_label . '" for="' . esc_attr( $id ) . '">' . $label_text . '</label>%2$s</div>'; 54 $items_markup = wp_dropdown_categories( $args ); 55 $type = 'dropdown'; 40 56 41 57 if ( ! is_admin() ) { … … 49 65 } 50 66 } else { 67 $args['show_option_none'] = $taxonomy->labels->no_terms; 68 51 69 $wrapper_markup = '<ul %1$s>%2$s</ul>'; 52 70 $items_markup = wp_list_categories( $args ); 53 71 $type = 'list'; 72 73 if ( ! empty( $block->context['enhancedPagination'] ) ) { 74 $p = new WP_HTML_Tag_Processor( $items_markup ); 75 while ( $p->next_tag( 'a' ) ) { 76 $p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' ); 77 } 78 $items_markup = $p->get_updated_html(); 79 } 54 80 } 55 81 … … 79 105 var dropdown = document.getElementById( '<?php echo esc_js( $dropdown_id ); ?>' ); 80 106 function onCatChange() { 81 if ( dropdown.options[ dropdown.selectedIndex ].value > 0) {82 location.href = "<?php echo esc_url( home_url() ); ?>/? cat="+ dropdown.options[ dropdown.selectedIndex ].value;107 if ( dropdown.options[ dropdown.selectedIndex ].value !== -1 ) { 108 location.href = "<?php echo esc_url( home_url() ); ?>/?" + dropdown.name + '=' + dropdown.options[ dropdown.selectedIndex ].value; 83 109 } 84 110 }
Note: See TracChangeset
for help on using the changeset viewer.