Forked from Jeff2Ma/woocommerce-featured-products.php
Created
February 15, 2017 06:39
-
-
Save jasperf/1600b748901f4907b801bf581dea15e0 to your computer and use it in GitHub Desktop.
woocommerce featured products
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 | |
//woocommerce featured products | |
//来自官方主题 wootique. | |
//CSS 样式请自己定义 | |
//或者采用以下短代码函数 | |
// <?php echo do_shortcode( '[featured_products per_page="12" columns="4"]' ); ?> | |
<div id="featured-products" class="<?php if ( get_option( 'woo_featured_product_style' ) == 'slider' ) { echo 'fp-slider'; } ?>"> | |
<h2><?php _e( 'Featured Products', 'woothemes' ); ?></h2> | |
<ul class="featured-products"> | |
<?php | |
$args = array( 'post_type' => 'product', 'posts_per_page' => get_option( 'woo_featured_product_limit' ), 'meta_key' => '_featured', 'meta_value' => 'yes' ); | |
$loop = new WP_Query( $args ); | |
while ( $loop->have_posts() ) : $loop->the_post(); $_product; | |
if ( function_exists( 'get_product' ) ) { | |
$_product = get_product( $loop->post->ID ); | |
} else { | |
$_product = new WC_Product( $loop->post->ID ); | |
} | |
?> | |
<li class="flipper"> | |
<div class="front"> | |
<?php woocommerce_show_product_sale_flash( $post, $_product ); ?> | |
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"> | |
<?php if ( has_post_thumbnail( $loop->post->ID ) ) echo get_the_post_thumbnail( $loop->post->ID, 'shop_thumbnail' ); else echo '<img src="' . $woocommerce->plugin_url() . '/assets/images/placeholder.png" alt="Placeholder" width="' . wc_get_image_size( 'shop_thumbnail_image_width' ) . 'px" height="' . wc_get_image_size( 'shop_thumbnail_image_height' ) . 'px" />'; ?> | |
</a> | |
</div><!--/.front--> | |
<div class="back"> | |
<h3><a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"> <?php the_title(); ?></a></h3> | |
<span class="price"><?php echo $_product->get_price_html(); ?></span> | |
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?> | |
</div><!--/.back--> | |
</li> | |
<?php endwhile; ?> | |
</ul> | |
<div class="clear"></div> | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment