'product_brand' ], $atts, 'brands_grouped' );
$taxonomy = sanitize_key( $atts['taxonomy'] );
// 1. Termes
$terms = get_terms( [ 'taxonomy' => $taxonomy, 'hide_empty' => true ] );
if ( empty( $terms ) || is_wp_error( $terms ) ) return '
Aucune marque trouvée.
';
// 2. Filtre : au moins 1 produit publié en stock
$filtered = [];
foreach ( $terms as $term ) {
$q = new WP_Query( [
'post_type' => 'product',
'post_status' => 'publish',
'tax_query' => [ [ 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $term->term_id ] ],
'meta_query' => [ [ 'key' => '_stock_status', 'value' => 'instock' ] ],
'posts_per_page' => 1,
'fields' => 'ids',
] );
if ( $q->have_posts() ) $filtered[] = $term;
wp_reset_postdata();
}
$terms = $filtered;
if ( empty( $terms ) ) return 'Aucune marque trouvée.
';
// 3. Tri alphabétique
usort( $terms, fn( $a, $b ) => strcasecmp( $a->name, $b->name ) );
// 4. Regroupement par lettre
$grouped = [];
foreach ( $terms as $term ) {
$letter = mb_strtoupper( mb_substr( $term->name, 0, 1 ) );
if ( ! preg_match( '/[A-Z]/', $letter ) ) $letter = '#';
$grouped[ $letter ][] = $term;
}
ksort( $grouped );
// 5. CSS
$uid = 'dpbi-' . substr( md5( $taxonomy ), 0, 6 );
$css = '
';
// 6. HTML
$letters_all = array_merge( [ '#' ], range( 'A', 'Z' ) );
$html = $css . '';
// -- Navigation --
$html .= '
';
// -- Sections --
foreach ( $grouped as $letter => $group ) {
$html .= '
';
$html .= '' . esc_html( $letter ) . '
';
$html .= '';
foreach ( $group as $term ) {
$link = get_term_link( $term );
$logo_html = '';
$logo_id = get_term_meta( $term->term_id, 'logo', true );
if ( $logo_id ) {
$logo_url = wp_get_attachment_image_url( (int) $logo_id, [ 50, 25 ] );
if ( $logo_url ) $logo_html = '
';
}
$html .= '- ' . $logo_html . '' . esc_html( $term->name ) . '
';
}
$html .= '
';
}
$html .= '
';
return $html;
}
add_shortcode( 'brands_grouped', 'afficher_brands_groupes_shortcode' );
https://divinparfum.fr/page-sitemap.xml
2026-04-20T14:33:09+00:00
https://divinparfum.fr/product-sitemap1.xml
2026-04-22T05:57:06+00:00
https://divinparfum.fr/product-sitemap2.xml
2026-04-22T05:54:56+00:00
https://divinparfum.fr/product-sitemap3.xml
2026-04-22T05:20:22+00:00
https://divinparfum.fr/product_brand-sitemap.xml
2026-04-22T05:57:06+00:00
https://divinparfum.fr/product_cat-sitemap.xml
2026-04-22T05:57:06+00:00
https://divinparfum.fr/createurs-sitemap.xml
2026-04-22T05:57:06+00:00
https://divinparfum.fr/famille-olfactive-sitemap.xml
2026-04-22T05:57:06+00:00
https://divinparfum.fr/local-sitemap.xml
2025-03-08T10:07:49+00:00