Skip to content

Commit

Permalink
loops template rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Jul 11, 2012
1 parent 7ac85e9 commit c846906
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 121 deletions.
9 changes: 7 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion shortcodes/shortcode-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
30 changes: 29 additions & 1 deletion templates/archive-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,37 @@
<?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 do_action('woocommerce_before_shop_loop'); ?>

<?php woocommerce_get_template_part( 'loop', 'shop' ); ?>
<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
Expand Down
97 changes: 48 additions & 49 deletions templates/content-product.php
Original file line number Diff line number Diff line change
@@ -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-
*/
?>

<?php
/**
* woocommerce_before_single_product hook
*
* @hooked woocommerce_show_messages - 10
*/
do_action( 'woocommerce_before_single_product' );
?>

global $product, $woocommerce_loop;

<div itemscope itemtype="http://schema.org/Product" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
// Store loop count we're currently on
if ( empty( $woocommerce_loop['loop'] ) )
$woocommerce_loop['loop'] = 0;

<?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' );
?>
// Store column count for displaying the grid
if ( empty( $woocommerce_loop['columns'] ) )
$woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 );

<div class="summary">
// Ensure visibilty
if ( ! $product->is_visible() ) return;

<?php
/**
* woocommerce_single_product_summary hook
// 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_shop_loop_item' ); ?>

<a href="<?php the_permalink(); ?>">

<?php
/**
* woocommerce_before_shop_loop_item_title 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' );
* @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>

</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' ); ?>
<?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>
62 changes: 62 additions & 0 deletions templates/content-product_cat.php
Original file line number Diff line number Diff line change
@@ -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>
64 changes: 64 additions & 0 deletions templates/content-single-product.php
Original file line number Diff line number Diff line change
@@ -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' ); ?>
37 changes: 0 additions & 37 deletions templates/loop-product-cats.php

This file was deleted.

2 changes: 1 addition & 1 deletion templates/single-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<?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. ?>

Expand Down
1 change: 0 additions & 1 deletion woocommerce-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

/* 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);
Expand Down
Loading

0 comments on commit c846906

Please sign in to comment.