jon-c
10/20/2014 - 5:46 PM

Get product brand thumbnails in a random order. Replaces [product_brand_thumbnails]

Get product brand thumbnails in a random order. Replaces [product_brand_thumbnails]

			<?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;?>