Created
October 20, 2014 17:46
-
-
Save jondcampbell/b9bfed11589fe593e924 to your computer and use it in GitHub Desktop.
Get product brand thumbnails in a random order. Replaces [product_brand_thumbnails]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This code is basically taken out of the product_brand_thumbnails shortcode and then we add in some shuffling of the order | |
$brands = get_terms( 'product_brand', array( 'hide_empty' => 0, 'orderby' => 'name', 'exclude' => '', 'number' => 5, 'order' => 'ASC' ) ); | |
if ($brands ): | |
$columns = 5; | |
// Randomly order the brands | |
shuffle($brands); | |
?> | |
<ul class="brand-thumbnails"> | |
<?php foreach ( $brands as $index => $brand ) : | |
$thumbnail = get_brand_thumbnail_url( $brand->term_id, apply_filters( 'woocommerce_brand_thumbnail_size', 'brand-thumb' ) ); | |
if ( ! $thumbnail ) | |
$thumbnail = woocommerce_placeholder_img_src(); | |
$class = ''; | |
if ( $index == 0 || $index % $columns == 0 ) | |
$class = 'first'; | |
elseif ( ( $index + 1 ) % $columns == 0 ) | |
$class = 'last'; | |
$width = floor( ( ( 100 - ( ( $columns - 1 ) * 2 ) ) / $columns ) * 100 ) / 100; | |
?> | |
<li class="<?php echo $class; ?>" style="width: <?php echo $width; ?>%;"> | |
<a href="<?php echo get_term_link( $brand->slug, 'product_brand' ); ?>" title="<?php echo $brand->name; ?>"> | |
<img src="<?php echo $thumbnail; ?>" alt="<?php echo $brand->name; ?>" /> | |
</a> | |
</li> | |
<?php endforeach; ?> | |
</ul> | |
<?php endif;?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment