<?php
function woo_tag_list(){
$output = '<div class="woo-tags">';
$args = array(
'hide_empty' => 0,
'orderby' => 'name',
'order'=> 'ASC'
);
$tax_name = 'product_tag'; //имя таксономии
$terms = get_terms($tax_name, $args );
$capital = '';
$i = 0;
$cols_number = 4; // Количество колонок для вывода
$cut = ceil( count( $terms ) / $cols_number );
$cutter = $cut;
$letter_i = 0;
$output .= '<div class="column">';
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$i ++;
$firstletter = mb_substr( $term->name, 0, 1 );
$firstletter = mb_strtoupper($firstletter);
if ( $firstletter != $capital ) {
$letter_i ++;
if ( $letter_i != 1 ) {
$output .= '</ul>';
}
if ( $i > $cutter ) {
$output .= '</div><div class="column">';
$cutter = $cutter + $cut;
}
$capital = $firstletter;
$output .= '<h4>' . $capital . '</h4><ul>';
}
$term = get_term_by( 'id', (int) $term->term_id, $tax_name );
$output .= '<li><a href="' . get_term_link( (int) $term->term_id, $tax_name ) . '">' . $term->name . '</a> (' . $term->count . ')</li>';
}
$output .= '</ul></div>';
return $output;
}else{
return 'Не найдено ни одной метки товаров';
}
}
add_shortcode( 'woo_tags', 'woo_tag_list' );
?>