= $limit ) { break; } $link = get_term_link( $term ); if ( ! is_string( $link ) ) { continue; } $count = self::count( $term ); $rows .= '
  • ' . ( $brands ? AIEO_Brand_Face::mark( $term, 'aieo-post-rows__mark' ) : self::picture( $term ) ) . '' . esc_html( $term->name ) . '' . ( $count > 0 ? '' . esc_html( sprintf( _n( '%s product', '%s products', $count, 'ai-eshop-optimizer' ), number_format_i18n( $count ) ) ) . '' : '' ) . '' . AIEO_Favourite::html( $brands ? 'brand' : 'product_cat', (int) $term->term_id, array( 'name' => $term->name, 'source' => 'post_rows', 'class' => 'aieo-post-rows__heart' ) ) . '
  • '; ++$shown; } if ( '' === $rows ) { return ''; } $heading = trim( (string) ( $args['heading'] ?? '' ) ); $heading = '' !== $heading ? $heading : ( $brands ? __( 'Brands', 'ai-eshop-optimizer' ) : __( 'Categories', 'ai-eshop-optimizer' ) ); $all = trim( (string) ( $args['all_href'] ?? '' ) ); $id = wp_unique_id( 'aieo-post-rows-' ); wp_enqueue_style( 'aieo-post-rows', plugins_url( 'post-rows.css', __FILE__ ), array(), (string) filemtime( __DIR__ . '/post-rows.css' ) ); return '
    'aieo-post-rows aieo-post-rows--' . $kind, 'aria-labelledby' => $id, 'data-rooster-ui' => 'rooster-one/post_related', ) ) . '>' . '

    ' . esc_html( $heading ) . '

    ' . '' . ( '' !== $all && count( $terms ) > $shown ? '

    ' . esc_html( $brands ? __( 'All brands', 'ai-eshop-optimizer' ) : __( 'All categories', 'ai-eshop-optimizer' ) ) . '

    ' : '' ) . '
    '; } public static function terms( $post_id, $taxonomy ) { $out = array(); foreach ( (array) AIEO_DMM_Term_Relations::for_post( (int) $post_id, 'post' ) as $rel ) { if ( ( $rel['taxonomy'] ?? '' ) !== $taxonomy ) { continue; } $term = get_term( (int) ( $rel['term_id'] ?? 0 ), $taxonomy ); if ( $term instanceof WP_Term ) { $out[ (int) $term->term_id ] = $term; } } return array_values( $out ); } private static function count( WP_Term $term ) { if ( 'product_brand' === $term->taxonomy && class_exists( 'AIEO_Core_Brand_Vitals' ) ) { $vitals = AIEO_Core_Brand_Vitals::instance()->get_by_id( (int) $term->term_id ); if ( is_array( $vitals ) && (int) $vitals['product_count'] > 0 ) { return (int) $vitals['product_count']; } } $wc = get_term_meta( (int) $term->term_id, 'product_count_' . $term->taxonomy, true ); return '' !== $wc ? (int) $wc : (int) $term->count; } private static function picture( WP_Term $term ) { $img = (int) get_term_meta( (int) $term->term_id, 'thumbnail_id', true ); if ( $img > 0 ) { $html = wp_get_attachment_image( $img, 'thumbnail', false, array( 'alt' => '', 'sizes' => '44px', 'loading' => 'lazy', 'decoding' => 'async' ) ); if ( '' !== $html ) { return ''; } } return ''; } } }