Last active
January 26, 2018 01:20
-
-
Save ediamin/1cf66a517d400f19524d to your computer and use it in GitHub Desktop.
WooCommerce Custom Query
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> | |
<?php | |
$args = array( | |
'post_type' => 'product', | |
'posts_per_page' => 3, | |
); | |
$query = new WP_Query( $args ); | |
?> | |
<?php while ( $query->have_posts() ) : $query->the_post(); ?> | |
<?php | |
$product_id = get_the_ID(); | |
$product = new WC_Product( $product_id ); | |
$cat_count = sizeof( get_the_terms( $product_id, 'product_cat' ) ); | |
$tag_count = sizeof( get_the_terms( $product_id, 'product_tag' ) ); | |
?> | |
<li> | |
<?php echo the_post_thumbnail( array(468, 352) ); ?> | |
<div class="caption"> | |
<h2><?php the_title(); ?></h2> | |
<h3><?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '</span>' ); ?></h3> | |
<h3><?php echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '</span>' ); ?></h3> | |
<p><?php the_excerpt(); ?> </p> | |
</div> | |
<div class="cl"></div> | |
</li> | |
<?php endwhile; // End of the loop. ?> | |
<?php wp_reset_query(); ?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment