Forked from UltimateWoo/custom-woocommerce-loop.php
Last active
August 29, 2015 14:25
-
-
Save nucab/971688a5315648247edb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
if ( is_shop() || is_product_category() || is_product_tag() ) { // Only run on shop archive pages, not single products or other pages | |
// Products per page | |
$per_page = 24; | |
if ( get_query_var( 'taxonomy' ) ) { // If on a product taxonomy archive (category or tag) | |
$args = array( | |
'post_type' => 'product', | |
'posts_per_page' => $per_page, | |
'paged' => get_query_var( 'paged' ), | |
'tax_query' => array( | |
array( | |
'taxonomy' => get_query_var( 'taxonomy' ), | |
'field' => 'slug', | |
'terms' => get_query_var( 'term' ), | |
), | |
), | |
); | |
} else { // On main shop page | |
$args = array( | |
'post_type' => 'product', | |
'orderby' => 'date', | |
'order' => 'DESC', | |
'posts_per_page' => $per_page, | |
'paged' => get_query_var( 'paged' ), | |
); | |
} | |
// Set the query | |
$products = new WP_Query( $args ); | |
// Standard loop | |
if ( $products->have_posts() ) : | |
while ( $products->have_posts() ) : $products->the_post(); | |
endwhile; | |
wp_reset_postdata(); | |
endif; | |
} else { // If not on archive page (cart, checkout, etc), do normal operations | |
woocommerce_content(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment