context['filterwell/queryId'] ) || ( ! $qlf_is_author && ! taxonomy_exists( $qlf_taxonomy ) ) ) { return; } $qlf_post_type = $block->context['filterwell/postType'] ?? 'post'; $qlf_hierarchical = ! $qlf_is_author && get_taxonomy( $qlf_taxonomy )->hierarchical; $qlf_display = in_array( $attributes['displayType'] ?? '', array( 'checkbox', 'radio', 'select', 'tags' ), true ) ? $attributes['displayType'] : 'checkbox'; // Las etiquetas son opción única (radio) o, si se permite, varias (casillas). $qlf_input = 'tags' === $qlf_display ? ( empty( $attributes['multiple'] ) ? 'radio' : 'checkbox' ) : $qlf_display; // Un contenido tiene un solo autor: con autores la lógica siempre es "cualquiera". $qlf_logic = ! $qlf_is_author && 'checkbox' === $qlf_input && 'and' === ( $attributes['logic'] ?? 'or' ) ? 'and' : 'or'; $qlf_show_count = ! empty( $attributes['showCounts'] ); $qlf_hide_empty = ! empty( $attributes['hideEmpty'] ); $qlf_order_by = 'count' === ( $attributes['orderBy'] ?? 'name' ) ? 'count' : 'name'; $qlf_title = ! empty( $attributes['label'] ) ? $attributes['label'] : ( $qlf_is_author ? __( 'Author', 'filterwell' ) : get_taxonomy( $qlf_taxonomy )->labels->name ); $qlf_all_label = FilterWell::text( $attributes, 'allLabel', $qlf_is_author ? _x( 'All', 'all authors', 'filterwell' ) : __( 'All', 'filterwell' ) ); $qlf_prefix = FilterWell::prefix( $block->context['filterwell/queryId'], ! empty( $block->context['filterwell/inherit'] ) ); // Términos a mostrar (solo en taxonomías jerárquicas): todos, solo los // principales o las subcategorías del término elegido (dos filas de // categorías). Las dos últimas son de opción única. $qlf_scope = $qlf_hierarchical && in_array( $attributes['termsScope'] ?? 'all', array( 'top', 'children' ), true ) ? $attributes['termsScope'] : 'all'; // En el archivo de esta taxonomía (p. ej. /category/diseno/) el filtro es de // opción única y cada opción lleva a la URL de archivo de su término. $qlf_archive = FilterWell::archive_term_for( $qlf_taxonomy, $qlf_prefix ); if ( $qlf_archive || 'all' !== $qlf_scope ) { $qlf_input = 'select' === $qlf_display ? 'select' : 'radio'; $qlf_logic = 'or'; } // Categoría madre de la fila de subcategorías (se define más abajo). $qlf_root = null; $qlf_all_url = $qlf_archive ? FilterWell::all_items_url( $qlf_post_type ) : ''; $qlf_term_url = function ( $term ) use ( $qlf_archive, &$qlf_all_url ) { if ( ! $qlf_archive ) { return ''; } $url = $term ? FilterWell::term_url( $term ) : $qlf_all_url; return $url ? $url : ''; }; $qlf_param = FilterWell::tax_param( $qlf_prefix, $qlf_taxonomy, $qlf_logic ); $qlf_request = FilterWell::get_request( $qlf_prefix ); $qlf_selected = $qlf_request['tax'][ $qlf_taxonomy ]['terms'] ?? array(); if ( $qlf_is_author ) { // Autores con contenidos publicados del tipo del bucle. $qlf_users = get_users( array( 'has_published_posts' => array( $qlf_post_type ), 'orderby' => 'count' === $qlf_order_by ? 'post_count' : 'display_name', 'order' => 'count' === $qlf_order_by ? 'DESC' : 'ASC', ) ); $qlf_terms = array_map( array( 'FilterWell', 'author_as_term' ), $qlf_users ); } else { $qlf_terms = get_terms( array( 'taxonomy' => $qlf_taxonomy, 'hide_empty' => false, 'orderby' => $qlf_order_by, 'order' => 'count' === $qlf_order_by ? 'DESC' : 'ASC', ) ); if ( is_wp_error( $qlf_terms ) ) { return; } } // Valor de la opción "Todas": sin filtro, salvo en la fila de subcategorías, // donde "Todas" es la categoría madre. $qlf_all_value = ''; // Fila de subcategorías sin nada que mostrar: se dibuja vacía y oculta, para // que el router tenga dónde ponerla cuando se elija una categoría. $qlf_empty_row = false; if ( 'all' !== $qlf_scope ) { // El término elegido (por el archivo o la URL) y su categoría raíz. $qlf_current = $qlf_selected ? get_term_by( 'slug', $qlf_selected[0], $qlf_taxonomy ) : null; $qlf_lineage = $qlf_current ? array_reverse( get_ancestors( $qlf_current->term_id, $qlf_taxonomy, 'taxonomy' ) ) : array(); if ( $qlf_current ) { $qlf_lineage[] = $qlf_current->term_id; } $qlf_root_id = $qlf_lineage ? $qlf_lineage[0] : 0; if ( 'top' === $qlf_scope ) { $qlf_terms = array_values( wp_list_filter( $qlf_terms, array( 'parent' => 0 ) ) ); $qlf_root = $qlf_root_id ? get_term( $qlf_root_id, $qlf_taxonomy ) : null; $qlf_selected = $qlf_root instanceof WP_Term ? array( $qlf_root->slug ) : array(); } else { // Sin categoría elegida, o si no tiene subcategorías, la fila no se muestra. $qlf_root = $qlf_root_id ? get_term( $qlf_root_id, $qlf_taxonomy ) : null; $qlf_terms = $qlf_root instanceof WP_Term ? array_values( wp_list_filter( $qlf_terms, array( 'parent' => $qlf_root_id ) ) ) : array(); $qlf_empty_row = ! $qlf_terms; // Elegida la raíz: "Todas"; elegida una subcategoría (o una más profunda): su rama. $qlf_branch = isset( $qlf_lineage[1] ) ? get_term( $qlf_lineage[1], $qlf_taxonomy ) : null; $qlf_selected = $qlf_branch instanceof WP_Term ? array( $qlf_branch->slug ) : array(); $qlf_all_value = $qlf_empty_row ? '' : $qlf_root->slug; $qlf_all_url = $qlf_archive && ! $qlf_empty_row ? FilterWell::term_url( $qlf_root ) : ''; } } // Ordena jerárquicamente: cada hijo justo después de su padre. if ( $qlf_hierarchical ) { $qlf_by_parent = array(); $qlf_ids = wp_list_pluck( $qlf_terms, 'term_id' ); foreach ( $qlf_terms as $qlf_term ) { $qlf_parent = in_array( $qlf_term->parent, $qlf_ids, true ) ? $qlf_term->parent : 0; $qlf_by_parent[ $qlf_parent ][] = $qlf_term; } $qlf_sorted = array(); $qlf_visit = function ( $parent, $depth ) use ( &$qlf_visit, &$qlf_sorted, $qlf_by_parent ) { foreach ( $qlf_by_parent[ $parent ] ?? array() as $term ) { $term->qlf_depth = $depth; $qlf_sorted[] = $term; $qlf_visit( $term->term_id, $depth + 1 ); } }; $qlf_visit( 0, 0 ); $qlf_terms = $qlf_sorted; } // Conteos según los demás filtros activos (como hace WooCommerce). $qlf_counts = $qlf_show_count || $qlf_hide_empty ? FilterWell::term_counts( $qlf_taxonomy, $block->context ) : array(); $qlf_is_empty = function ( $term ) use ( $qlf_hide_empty, $qlf_counts, $qlf_selected ) { return $qlf_hide_empty && empty( $qlf_counts[ $term->term_id ] ) && ! in_array( $term->slug, $qlf_selected, true ); }; // Región del router: al filtrar se reemplaza con los conteos y opciones actualizados. $qlf_arrows = 'tags' === $qlf_display && ( $attributes['tagsArrows'] ?? true ); // Tamaño de las flechas: solo valores simples en px, em o rem. $qlf_arrow_size = preg_match( '/^\d+(\.\d+)?(px|em|rem)$/', (string) ( $attributes['tagsArrowSize'] ?? '' ) ) ? $attributes['tagsArrowSize'] : ''; $qlf_classes = array( 'is-style-' . $qlf_display ); if ( 'tags' === $qlf_display ) { $qlf_classes[] = 'is-scroll-' . ( 'mobile' === ( $attributes['tagsScroll'] ?? 'always' ) ? 'mobile' : 'always' ); $qlf_classes[] = 'is-justify-' . ( in_array( $attributes['tagsJustify'] ?? 'left', array( 'center', 'right' ), true ) ? $attributes['tagsJustify'] : 'left' ); } $qlf_wrapper_args = array( 'class' => implode( ' ', $qlf_classes ), 'style' => FilterWell::option_color_style( $attributes ), 'data-wp-interactive' => 'filterwell', 'data-wp-router-region' => FilterWell::region_id( 'qlf-tax-' . $qlf_param ), ); // Las etiquetas filtran al instante, como una navegación. if ( 'tags' === $qlf_display ) { $qlf_wrapper_args['data-qlf-instant'] = 'true'; } $qlf_wrapper = get_block_wrapper_attributes( $qlf_wrapper_args ); if ( $qlf_empty_row ) { echo ''; return; } ?>
> 'true' ) ) ); } ?>
data-wp-context='{"canPrev":false,"canNext":false}' data-wp-class--can-scroll-prev="context.canPrev" data-wp-class--can-scroll-next="context.canNext" data-wp-init="callbacks.initTags" data-wp-watch="callbacks.updateTags" >