Created
December 21, 2017 05:59
-
-
Save jessbudd/66335479ac69391e038d85dfc95e94a4 to your computer and use it in GitHub Desktop.
Woocoomerce product loop
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 | |
$args = array( | |
'post_type' => 'product', | |
'stock' => 1, | |
'posts_per_page' => 4, //how many products to show | |
'tax_query' => array( //query the product catagories | |
array( | |
'taxonomy' => 'product_cat', | |
'field' => 'slug', | |
'terms' => array( 'catalogues' ), | |
'operator' => 'NOT IN' //remove category above from query | |
) | |
), | |
'orderby' =>'date', //sorted by date, could be others | |
'order' => 'DESC' ); | |
$loop = new WP_Query( $args ); | |
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?> | |
//each product result returned contains this code | |
<div class="recent-product grid-25 tablet-grid-50"> | |
<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> | |
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="My Image Placeholder" width="65px" height="115px" />'; ?> | |
<h3><?php the_title(); ?></h3> | |
<!--<span class="price"><?php echo $product->get_price_html(); ?></span>--> | |
</a> | |
<!--<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>--> | |
</div><!-- /new-arrival--> | |
<?php endwhile; ?> | |
<?php wp_reset_query(); ?> | |
//close product div | |
</div><!--list-container--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment