loops template rewrite
This commit is contained in:
parent
7ac85e9e27
commit
c846906064
|
@ -150,10 +150,12 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
|
||||
== Changelog ==
|
||||
|
||||
= 1.xxxx - xx/xx/2012 =
|
||||
= 1.6 - xx/xx/2012 =
|
||||
* Feature - Support for ounces
|
||||
* Feature - Restore coupon usage count after order cancellation
|
||||
* Templating - Dumped woocommerce_single_product_content(), woocommerce_archive_product_content(), woocommerce_product_taxonomy_content() and introduced a content-product.php template for ease of customisation.
|
||||
* Templating - Abolished the use of query_posts.
|
||||
* Templating - Introduced content-product.php and content-product_cat.php for use in loops. Loop-shop is gone.
|
||||
* Templating - Dumped woocommerce_single_product_content(), woocommerce_archive_product_content(), woocommerce_product_taxonomy_content() in favour of the new content templates.
|
||||
* Templating - Documented templates listing hooked in functions.
|
||||
* Tweak - Better WC_Product::get_image() function. Fixed instances where we were not echo'ing.
|
||||
* Tweak - Pass valuable object data to woocommerce_email_headers and woocommerce_email_attachments filters.
|
||||
|
@ -935,6 +937,9 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
|
||||
== Upgrade Notice ==
|
||||
|
||||
= 1.6 =
|
||||
1.6 introduces some template changes, for loops in particular. See the changelog for details and ensure theme compatibility before upgrading.
|
||||
|
||||
= 1.5.4 =
|
||||
Please update your shipping methods after upgrading - the save hooks have been modified to ensure settings are saved more reliably.
|
||||
|
||||
|
|
|
@ -425,7 +425,7 @@ function woocommerce_product_page_shortcode( $atts ) {
|
|||
|
||||
<div class="single-product">
|
||||
|
||||
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
|
||||
<?php woocommerce_get_template_part( 'content', 'single-product' ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
|
@ -44,9 +44,37 @@ get_header('shop'); ?>
|
|||
<?php elseif ( ! is_search() && get_query_var( 'paged' ) == 0 && ! empty( $shop_page ) && is_object( $shop_page ) ) : ?>
|
||||
<?php echo '<div class="page-description">' . apply_filters( 'the_content', $shop_page->post_content ) . '</div>'; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( have_posts() ) : ?>
|
||||
|
||||
<?php woocommerce_get_template_part( 'loop', 'shop' ); ?>
|
||||
<?php do_action('woocommerce_before_shop_loop'); ?>
|
||||
|
||||
<ul class="products">
|
||||
|
||||
<?php woocommerce_product_subcategories(); ?>
|
||||
|
||||
<?php while ( have_posts() ) : the_post(); ?>
|
||||
|
||||
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
|
||||
|
||||
<?php endwhile; // end of the loop. ?>
|
||||
|
||||
</ul>
|
||||
|
||||
<?php do_action('woocommerce_after_shop_loop'); ?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<?php if ( ! woocommerce_product_subcategories( array( 'before' => '<ul class="products">', 'after' => '</ul>' ) ) ) : ?>
|
||||
|
||||
<p><?php _e( 'No products found which match your selection.', 'woocommerce' ); ?></p>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="clear"></div>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_pagination hook
|
||||
|
|
|
@ -1,64 +1,63 @@
|
|||
<?php
|
||||
/**
|
||||
* The template for displaying content in the single-product.php template
|
||||
* The template for displaying product content within loops.
|
||||
*
|
||||
* Override this template by copying it to yourtheme/woocommerce/content-product.php
|
||||
*
|
||||
* @package WooCommerce
|
||||
* @since WooCommerce 1.6
|
||||
* @todo prepend class names with wc-
|
||||
*/
|
||||
|
||||
global $product, $woocommerce_loop;
|
||||
|
||||
// Store loop count we're currently on
|
||||
if ( empty( $woocommerce_loop['loop'] ) )
|
||||
$woocommerce_loop['loop'] = 0;
|
||||
|
||||
// Store column count for displaying the grid
|
||||
if ( empty( $woocommerce_loop['columns'] ) )
|
||||
$woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 );
|
||||
|
||||
// Ensure visibilty
|
||||
if ( ! $product->is_visible() ) return;
|
||||
|
||||
// Increase loop count
|
||||
$woocommerce_loop['loop']++;
|
||||
?>
|
||||
<li class="product <?php
|
||||
if ( $woocommerce_loop['loop'] % $woocommerce_loop['columns'] == 0 )
|
||||
echo 'last';
|
||||
elseif ( ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] == 0 )
|
||||
echo 'first';
|
||||
?>">
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_before_single_product hook
|
||||
*
|
||||
* @hooked woocommerce_show_messages - 10
|
||||
*/
|
||||
do_action( 'woocommerce_before_single_product' );
|
||||
?>
|
||||
|
||||
<div itemscope itemtype="http://schema.org/Product" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_show_product_images hook
|
||||
*
|
||||
* @hooked woocommerce_show_product_sale_flash - 10
|
||||
* @hooked woocommerce_show_product_images - 20
|
||||
*/
|
||||
do_action( 'woocommerce_before_single_product_summary' );
|
||||
?>
|
||||
|
||||
<div class="summary">
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_single_product_summary hook
|
||||
*
|
||||
* @hooked woocommerce_template_single_title - 5
|
||||
* @hooked woocommerce_template_single_price - 10
|
||||
* @hooked woocommerce_template_single_excerpt - 20
|
||||
* @hooked woocommerce_template_single_add_to_cart - 30
|
||||
* @hooked woocommerce_template_single_meta - 40
|
||||
* @hooked woocommerce_template_single_sharing - 50
|
||||
*/
|
||||
do_action( 'woocommerce_single_product_summary' );
|
||||
?>
|
||||
|
||||
</div><!-- .summary -->
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_after_single_product_summary hook
|
||||
*
|
||||
* @hooked woocommerce_output_product_data_tabs - 10
|
||||
* @hooked woocommerce_output_related_products - 20
|
||||
*/
|
||||
do_action( 'woocommerce_after_single_product_summary' );
|
||||
?>
|
||||
<?php do_action( 'woocommerce_before_shop_loop_item' ); ?>
|
||||
|
||||
<a href="<?php the_permalink(); ?>">
|
||||
|
||||
</div><!-- #product-<?php the_ID(); ?> -->
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_before_shop_loop_item_title hook
|
||||
*
|
||||
* @hooked woocommerce_show_product_loop_sale_flash - 10
|
||||
* @hooked woocommerce_template_loop_product_thumbnail - 10
|
||||
*/
|
||||
do_action( 'woocommerce_before_shop_loop_item_title' );
|
||||
?>
|
||||
|
||||
<h3><?php the_title(); ?></h3>
|
||||
|
||||
<?php do_action( 'woocommerce_after_single_product' ); ?>
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_after_shop_loop_item_title hook
|
||||
*
|
||||
* @hooked woocommerce_template_loop_price - 10
|
||||
*/
|
||||
do_action( 'woocommerce_after_shop_loop_item_title' );
|
||||
?>
|
||||
|
||||
</a>
|
||||
|
||||
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
|
||||
|
||||
</li>
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/**
|
||||
* The template for displaying product category thumbnails within loops.
|
||||
*
|
||||
* Override this template by copying it to yourtheme/woocommerce/content-product_cat.php
|
||||
*
|
||||
* @package WooCommerce
|
||||
* @since WooCommerce 1.6
|
||||
*/
|
||||
|
||||
global $woocommerce_loop;
|
||||
|
||||
// Store loop count we're currently on
|
||||
if ( empty( $woocommerce_loop['loop'] ) )
|
||||
$woocommerce_loop['loop'] = 0;
|
||||
|
||||
// Store column count for displaying the grid
|
||||
if ( empty( $woocommerce_loop['columns'] ) )
|
||||
$woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 );
|
||||
|
||||
// Increase loop count
|
||||
$woocommerce_loop['loop']++;
|
||||
?>
|
||||
<li class="product <?php
|
||||
if ( $woocommerce_loop['loop'] % $woocommerce_loop['columns'] == 0 )
|
||||
echo 'last';
|
||||
elseif ( ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] == 0 )
|
||||
echo 'first';
|
||||
?>">
|
||||
|
||||
<?php do_action( 'woocommerce_before_subcategory', $category ); ?>
|
||||
|
||||
<a href="<?php echo get_term_link( $category->slug, 'product_cat' ); ?>">
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_before_subcategory_title hook
|
||||
*
|
||||
* @hooked woocommerce_subcategory_thumbnail - 10
|
||||
*/
|
||||
do_action( 'woocommerce_before_subcategory_title', $category );
|
||||
?>
|
||||
|
||||
<h3>
|
||||
<?php echo $category->name; ?>
|
||||
<?php if ( $category->count > 0 ) : ?>
|
||||
<mark class="count">(<?php echo $category->count; ?>)</mark>
|
||||
<?php endif; ?>
|
||||
</h3>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_after_subcategory_title hook
|
||||
*/
|
||||
do_action( 'woocommerce_after_subcategory_title', $category );
|
||||
?>
|
||||
|
||||
</a>
|
||||
|
||||
<?php do_action( 'woocommerce_after_subcategory', $category ); ?>
|
||||
|
||||
</li>
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* The template for displaying product content in the single-product.php template
|
||||
*
|
||||
* Override this template by copying it to yourtheme/woocommerce/content-single-product.php
|
||||
*
|
||||
* @package WooCommerce
|
||||
* @since WooCommerce 1.6
|
||||
* @todo prepend class names with wc-
|
||||
*/
|
||||
?>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_before_single_product hook
|
||||
*
|
||||
* @hooked woocommerce_show_messages - 10
|
||||
*/
|
||||
do_action( 'woocommerce_before_single_product' );
|
||||
?>
|
||||
|
||||
<div itemscope itemtype="http://schema.org/Product" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_show_product_images hook
|
||||
*
|
||||
* @hooked woocommerce_show_product_sale_flash - 10
|
||||
* @hooked woocommerce_show_product_images - 20
|
||||
*/
|
||||
do_action( 'woocommerce_before_single_product_summary' );
|
||||
?>
|
||||
|
||||
<div class="summary">
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_single_product_summary hook
|
||||
*
|
||||
* @hooked woocommerce_template_single_title - 5
|
||||
* @hooked woocommerce_template_single_price - 10
|
||||
* @hooked woocommerce_template_single_excerpt - 20
|
||||
* @hooked woocommerce_template_single_add_to_cart - 30
|
||||
* @hooked woocommerce_template_single_meta - 40
|
||||
* @hooked woocommerce_template_single_sharing - 50
|
||||
*/
|
||||
do_action( 'woocommerce_single_product_summary' );
|
||||
?>
|
||||
|
||||
</div><!-- .summary -->
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_after_single_product_summary hook
|
||||
*
|
||||
* @hooked woocommerce_output_product_data_tabs - 10
|
||||
* @hooked woocommerce_output_related_products - 20
|
||||
*/
|
||||
do_action( 'woocommerce_after_single_product_summary' );
|
||||
?>
|
||||
|
||||
</div><!-- #product-<?php the_ID(); ?> -->
|
||||
|
||||
<?php do_action( 'woocommerce_after_single_product' ); ?>
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
global $woocommerce, $woocommerce_loop, $product_category_found;
|
||||
|
||||
$product_category_found = false;
|
||||
|
||||
?>
|
||||
|
||||
<?php
|
||||
foreach ($product_categories as $category) :
|
||||
|
||||
if ($category->parent != $product_category_parent) continue;
|
||||
|
||||
$product_category_found = true;
|
||||
|
||||
$woocommerce_loop['loop']++;
|
||||
?>
|
||||
<li class="product sub-category <?php if ($woocommerce_loop['loop']%$woocommerce_loop['columns']==0) echo 'last'; if (($woocommerce_loop['loop']-1)%$woocommerce_loop['columns']==0) echo 'first'; ?>">
|
||||
|
||||
<?php do_action('woocommerce_before_subcategory', $category); ?>
|
||||
|
||||
<a href="<?php echo get_term_link($category->slug, 'product_cat'); ?>">
|
||||
|
||||
<?php do_action('woocommerce_before_subcategory_title', $category); ?>
|
||||
|
||||
<h3><?php echo $category->name; ?> <?php if ($category->count>0) : ?><mark class="count">(<?php echo $category->count; ?>)</mark><?php endif; ?></h3>
|
||||
|
||||
<?php do_action('woocommerce_after_subcategory_title', $category); ?>
|
||||
|
||||
</a>
|
||||
|
||||
<?php do_action('woocommerce_after_subcategory', $category); ?>
|
||||
|
||||
</li><?php
|
||||
|
||||
endforeach;
|
||||
?>
|
|
@ -22,7 +22,7 @@ get_header('shop'); ?>
|
|||
|
||||
<?php while ( have_posts() ) : the_post(); ?>
|
||||
|
||||
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
|
||||
<?php woocommerce_get_template_part( 'content', 'single-product' ); ?>
|
||||
|
||||
<?php endwhile; // end of the loop. ?>
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ if ( !is_admin() || defined('DOING_AJAX') ) {
|
|||
|
||||
/* Products Loop */
|
||||
add_action( 'woocommerce_before_shop_loop', 'woocommerce_show_messages', 10 );
|
||||
add_action( 'woocommerce_before_shop_loop_products', 'woocommerce_product_subcategories' );
|
||||
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
|
||||
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
|
||||
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
|
||||
|
|
|
@ -21,7 +21,7 @@ if ( ! function_exists( 'woocommerce_content' ) ) {
|
|||
|
||||
while ( have_posts() ) : the_post();
|
||||
|
||||
woocommerce_get_template_part( 'content', 'product' );
|
||||
woocommerce_get_template_part( 'content', 'single-product' );
|
||||
|
||||
endwhile;
|
||||
|
||||
|
@ -484,49 +484,81 @@ if ( ! function_exists( 'woocommerce_checkout_coupon_form' ) ) {
|
|||
* display product sub categories as thumbnails
|
||||
**/
|
||||
if ( ! function_exists( 'woocommerce_product_subcategories' ) ) {
|
||||
function woocommerce_product_subcategories() {
|
||||
global $woocommerce, $woocommerce_loop, $wp_query, $wp_the_query, $_chosen_attributes, $product_category_found;
|
||||
function woocommerce_product_subcategories( $args = array() ) {
|
||||
global $woocommerce, $wp_query, $_chosen_attributes;
|
||||
|
||||
$defaults = array(
|
||||
'before' => '',
|
||||
'after' => ''
|
||||
);
|
||||
|
||||
if ( $wp_query !== $wp_the_query ) return; // Detect main query
|
||||
if ( sizeof( $_chosen_attributes ) >0 || ( isset( $_GET['max_price'] ) && isset( $_GET['min_price'] ) ) ) return; // Don't show when filtering
|
||||
if ( is_search() ) return;
|
||||
if ( ! is_product_category() && ! is_shop() ) return;
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
extract( $args, EXTR_SKIP );
|
||||
|
||||
// Don't show when filtering
|
||||
if ( sizeof( $_chosen_attributes ) > 0 || ( isset( $_GET['max_price'] ) && isset( $_GET['min_price'] ) ) ) return;
|
||||
|
||||
// Don't show when searching or when on page > 1 and ensure we're on a product archive
|
||||
if ( is_search() || is_paged() || ( ! is_product_category() && ! is_shop() ) ) return;
|
||||
|
||||
// Check cateogries are enabled
|
||||
if ( is_product_category() && get_option( 'woocommerce_show_subcategories' ) == 'no' ) return;
|
||||
if ( is_shop() && get_option( 'woocommerce_shop_show_subcategories' ) == 'no' ) return;
|
||||
if ( is_paged() ) return;
|
||||
|
||||
if ( $product_cat_slug = get_query_var( 'product_cat' ) ) :
|
||||
$product_cat = get_term_by( 'slug', $product_cat_slug, 'product_cat' );
|
||||
$product_category_parent = $product_cat->term_id;
|
||||
else :
|
||||
$product_category_parent = 0;
|
||||
endif;
|
||||
// Find the category + category parent, if applicable
|
||||
if ( $product_cat_slug = get_query_var( 'product_cat' ) ) {
|
||||
$product_cat = get_term_by( 'slug', $product_cat_slug, 'product_cat' );
|
||||
$product_category_parent = $product_cat->term_id;
|
||||
} else {
|
||||
$product_category_parent = 0;
|
||||
}
|
||||
|
||||
// NOTE: using child_of instead of parent - this is not ideal but due to a WP bug ( http://core.trac.wordpress.org/ticket/15626 ) pad_counts won't work
|
||||
$args = array(
|
||||
'child_of' => $product_category_parent,
|
||||
'menu_order' => 'ASC',
|
||||
'hide_empty' => 1,
|
||||
'hierarchical' => 1,
|
||||
'taxonomy' => 'product_cat',
|
||||
'pad_counts' => 1
|
||||
'child_of' => $product_category_parent,
|
||||
'menu_order' => 'ASC',
|
||||
'hide_empty' => 1,
|
||||
'hierarchical' => 1,
|
||||
'taxonomy' => 'product_cat',
|
||||
'pad_counts' => 1
|
||||
);
|
||||
$product_categories = get_categories( $args );
|
||||
|
||||
$product_category_found = false;
|
||||
|
||||
if ( $product_categories ) {
|
||||
|
||||
woocommerce_get_template( 'loop-product-cats.php', array(
|
||||
'product_categories' => $product_categories,
|
||||
'product_category_parent' => $product_category_parent
|
||||
|
||||
foreach ( $product_categories as $category ) {
|
||||
|
||||
if ( $category->parent != $product_category_parent )
|
||||
continue;
|
||||
|
||||
if ( ! $product_category_found ) {
|
||||
// We found a category
|
||||
$product_category_found = true;
|
||||
echo $before;
|
||||
}
|
||||
|
||||
woocommerce_get_template( 'content-product_cat.php', array(
|
||||
'category' => $category
|
||||
) );
|
||||
|
||||
// If we are hiding products disable the loop and pagination
|
||||
if ( $product_category_found == true && get_option( 'woocommerce_hide_products_when_showing_subcategories' ) == 'yes' ) {
|
||||
$woocommerce_loop['show_products'] = false;
|
||||
$wp_query->max_num_pages = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// If we are hiding products disable the loop and pagination
|
||||
if ( $product_category_found == true && get_option( 'woocommerce_hide_products_when_showing_subcategories' ) == 'yes' ) {
|
||||
$wp_query->post_count = 0;
|
||||
$wp_query->max_num_pages = 0;
|
||||
}
|
||||
|
||||
if ( $product_category_found ) {
|
||||
echo $after;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue