Last active
August 29, 2015 14:02
-
-
Save cezarpopa/946f4f6e4b5f9596c937 to your computer and use it in GitHub Desktop.
Woocommerce query products and set different thumbnail using count
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
<ul class="products"> | |
<?php | |
global $product; | |
$mimo_product_query = new WP_Query( | |
array( | |
'post_type' => 'product', | |
'orderby' => 'date', | |
'order' => 'desc', | |
'posts_per_page' => 2 | |
) | |
); | |
if( $mimo_product_query->posts ) { ?> | |
<?php $mimo_count=0; | |
foreach( $mimo_product_query->posts as $post ) : setup_postdata( $post ); $mimo_count++; ?> | |
<li class="product type-product <?php if( $mimo_count==1 ) { echo "col_4"; } else if ( $mimo_count==2 ) { echo "col_8"; } ?>"> | |
<div class="product-item-thumb-wrap"> | |
<?php if( $mimo_count==1 ) { ?> | |
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark" class="thumbnail"> | |
<img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ), 250, 200, true, true, true ) ?>" alt="<?php echo the_title(); ?>" /> | |
</a> | |
<?php } else if ( $mimo_count==2 ){ ?> | |
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark" class="thumbnail"> | |
<img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ), 350, 200, true, true, true ) ?>" alt="<?php echo the_title(); ?>" /> | |
</a> | |
<?php } ?> | |
</div> | |
<?php global $post, $product; ?> | |
<?php if (($product->is_type('simple') || $product->is_type('variable')) && get_option('woocommerce_enable_sku')=='yes') : ?> | |
<span itemprop="productID" class="sku"><?php _e('SKU:', 'woocommerce'); ?> <?php echo $product->sku; ?>.</span> | |
<?php endif; ?> | |
<span class="price"><?php echo $product->get_price_html(); ?></span> | |
<?php | |
global $product; | |
echo apply_filters( 'woocommerce_loop_add_to_cart_link', | |
sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>', | |
esc_url( $product->add_to_cart_url() ), | |
esc_attr( $product->id ), | |
esc_attr( $product->get_sku() ), | |
$product->is_purchasable() ? 'add_to_cart_button' : '', | |
esc_attr( $product->product_type ), | |
esc_html( $product->add_to_cart_text() ) | |
), $product ); | |
?> | |
</li> | |
<?php if( $mimo_count==2 ) { $mimo_count=0; } endforeach; ?> | |
<?php } wp_reset_postdata(); $mimo_product_query = NULL; ?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment