Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode( 'electro_brands', 'ec_child_list_brands' );
- function ec_child_list_brands( $atts ) {
- $attributes = shortcode_atts( array(
- 'columns' => 4,
- 'ids' => '',
- ), $atts );
- $taxonomy_args = array(
- 'orderby' => 'title',
- 'order' => 'ASC',
- 'number' => 12,
- 'hide_empty' => false
- );
- $brand_taxonomy = electro_get_brands_taxonomy();
- $brand = get_taxonomy( $brand_taxonomy );
- if( ! empty( $brand_taxonomy ) ) {
- $terms = get_terms( $brand_taxonomy, $taxonomy_args );
- if( ! is_wp_error( $terms ) && !empty( $terms ) ) {
- ?><div class="brands-list columns-<?php echo esc_attr( $attributes['columns'] ); ?>"><?php foreach ( $terms as $term ) : ?>
- <div class="item">
- <?php if ( $brand->public ) : ?>
- <a href="<?php echo esc_url( apply_filters( 'ec_brand_link', get_term_link( $term ), $term ) ); ?>">
- <?php endif; ?>
- <figure>
- <figcaption class="text-overlay">
- <div class="info">
- <h4><?php echo esc_html( $term->name ); ?></h4>
- </div><!-- /.info -->
- </figcaption>
- <?php
- $thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
- $image_attributes = '';
- if ( $thumbnail_id ) {
- $image_attributes = wp_get_attachment_image_src( $thumbnail_id, 'full' );
- if( $image_attributes ) {
- $image_src = $image_attributes[0];
- $image_width = $image_attributes[1];
- $image_height = $image_attributes[2];
- }
- }
- if ( empty( $image_attributes ) ) {
- $dimensions = wc_get_image_size( 'shop_thumbnail' );
- $image_src = wc_placeholder_img_src();
- $image_width = $dimensions['width'];
- $image_height = $dimensions['height'];
- }
- $image_src = str_replace( ' ', '%20', $image_src );
- ?>
- <img src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr( $term->name ); ?>" width="<?php echo esc_attr( $image_width ); ?>" height="<?php echo esc_attr( $image_height ); ?>" class="img-responsive">
- </figure>
- <?php if ( $brand->public ) : ?>
- </a>
- <?php endif; ?>
- </div><!-- /.item -->
- <?php endforeach; ?></div><?php
- }
- }
- }
Add Comment
Please, Sign In to add comment