Guest User

Untitled

a guest
Mar 21st, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. add_shortcode( 'electro_brands', 'ec_child_list_brands' );
  2.  
  3. function ec_child_list_brands( $atts ) {
  4.  
  5. $attributes = shortcode_atts( array(
  6. 'columns' => 4,
  7. 'ids' => '',
  8. ), $atts );
  9.  
  10. $taxonomy_args = array(
  11. 'orderby' => 'title',
  12. 'order' => 'ASC',
  13. 'number' => 12,
  14. 'hide_empty' => false
  15. );
  16.  
  17. $brand_taxonomy = electro_get_brands_taxonomy();
  18. $brand = get_taxonomy( $brand_taxonomy );
  19.  
  20. if( ! empty( $brand_taxonomy ) ) {
  21.  
  22. $terms = get_terms( $brand_taxonomy, $taxonomy_args );
  23.  
  24. if( ! is_wp_error( $terms ) && !empty( $terms ) ) {
  25. ?><div class="brands-list columns-<?php echo esc_attr( $attributes['columns'] ); ?>"><?php foreach ( $terms as $term ) : ?>
  26.  
  27. <div class="item">
  28. <?php if ( $brand->public ) : ?>
  29. <a href="<?php echo esc_url( apply_filters( 'ec_brand_link', get_term_link( $term ), $term ) ); ?>">
  30. <?php endif; ?>
  31. <figure>
  32. <figcaption class="text-overlay">
  33. <div class="info">
  34. <h4><?php echo esc_html( $term->name ); ?></h4>
  35. </div><!-- /.info -->
  36. </figcaption>
  37. <?php
  38. $thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
  39. $image_attributes = '';
  40.  
  41. if ( $thumbnail_id ) {
  42.  
  43. $image_attributes = wp_get_attachment_image_src( $thumbnail_id, 'full' );
  44.  
  45. if( $image_attributes ) {
  46. $image_src = $image_attributes[0];
  47. $image_width = $image_attributes[1];
  48. $image_height = $image_attributes[2];
  49. }
  50. }
  51.  
  52.  
  53. if ( empty( $image_attributes ) ) {
  54.  
  55. $dimensions = wc_get_image_size( 'shop_thumbnail' );
  56. $image_src = wc_placeholder_img_src();
  57. $image_width = $dimensions['width'];
  58. $image_height = $dimensions['height'];
  59. }
  60.  
  61. $image_src = str_replace( ' ', '%20', $image_src );
  62. ?>
  63. <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">
  64. </figure>
  65. <?php if ( $brand->public ) : ?>
  66. </a>
  67. <?php endif; ?>
  68. </div><!-- /.item -->
  69.  
  70. <?php endforeach; ?></div><?php
  71. }
  72. }
  73. }
Add Comment
Please, Sign In to add comment