Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mp_display_products($query = '', $display){
- wp_reset_query();
- //$new_query_wp = new WP_Query($query) ;
- $new_query = query_posts($query) ;
- wp_simple_pagination(/*array('base' => 'store/products')*/);
- $i = 1 ;
- if($display == 'row'){
- echo '<table summary="Display featured products in rows" id="products-list">' ;
- }
- if ( $new_query != '' ) : ?>
- <?php /* Start the Loop */ ?>
- <?php foreach ($new_query as $post) {
- $sale_price = get_post_meta($post->ID, 'mp_sale_price', true) ;
- $sale_price = $sale_price[0] ;
- $price = get_post_meta($post->ID, 'mp_price', true) ;
- //Determines end_price
- if($sale_price == 0){
- //End price is normal price
- $end_price = '$'.$price[0] ;
- }
- else{
- //Or end price is sale price
- $end_price = '$'.$sale_price ;
- }
- //If theres a sale price
- if($sale_price != 0){
- //We display
- $price = 'RRP: <span class="price">$'.$price[0].'</span>' ;
- }
- else{
- //Or we don't
- $price = "" ;
- }
- ?>
- <?php //We display each product
- //Let's shorten the title string
- $title = $post->post_title ;
- $string_size = 25 ;
- //Test if string is longer that string_size
- if(strlen($title) > $string_size){
- $title = substr($title, 0, $string_size).'...' ;
- }
- //Check if we need a grid of a row display
- if($display == 'grid'){
- //Inventory
- $inventory = get_post_meta($post->ID, 'mp_inventory', true) ;
- ?>
- <article class="post-<?php echo $post->ID ; ?> product post-product-<?php echo $i ; ?>">
- <h2><a href="<?php echo get_permalink( $post->ID ) ; ?>" title="View product: <?php echo $post->post_title ; ?>"><?php echo $title ; ?></a></h2>
- <?php //Test if there is a thumbnail
- if(has_post_thumbnail($post->ID)){
- echo '<div class="image_product">' ;
- mp_product_image( $echo = true, $context = 'list', $post->ID, $size = 200 ) ;
- echo '</div><!--end thumbnail-->' ;
- }
- else{
- echo '<div class="image_product">
- <img src="'.get_template_directory_uri().'/images/default-product.png" alt="Default image for product" />
- </div>' ;
- }
- ?>
- <div class="product-details">
- <span class="product-old-price"><?php echo $price ; ?></span>
- <span class="product-detail-link"><a href="<?php echo get_permalink($post->ID) ; ?>">Details</a></span>
- <span class="product-price"><?php echo $end_price ; ?></span>
- <?php
- //If inventory isn't empty
- if(!empty($inventory)){
- mp_buy_button( $echo = true, $context = 'list', $post_id = $post->ID ) ;
- }
- ?>
- </div>
- </article>
- <?php
- }//end grid display
- //Start row
- else{
- echo '<tr>
- <td>' ;
- if(has_post_thumbnail($post->ID)){
- echo '<div class="image_product">' ;
- mp_product_image( $echo = true, $context = 'list', $post->ID, $size = 88 ) ;
- echo '</div><!--end thumbnail-->' ;
- }
- else{
- echo '<div class="image_product">
- <img src="'.get_template_directory_uri().'/images/default-product.png" alt="Default image for product" />
- </div>' ;
- }
- echo '</td>
- <td class="title"><h2><a href="'.get_permalink( $post->ID ).'" title="View product: '.$post->post_title.'">'.$post->post_title.'</a></h2>
- <span class="product-detail-link"><a href="'.get_permalink( $post->ID ).'">Details</a></span></td>
- <td>Customer Rating:' ;
- if(function_exists('kk_star_ratings')) : echo kk_star_ratings($post->ID); endif;
- $comments_count = wp_count_comments( $post->ID );
- echo '<span class="reviews">Reviews ('.$comments_count->approved.')</span></td>
- <td class="price"><span class="product-price">'.$end_price.'</span>';
- mp_buy_button( $echo = true, $context = 'list', $post_id = $post->ID ) ;
- echo '</td></tr>' ;
- }
- $i++ ;
- if($i == 4){ $i = 1 ; }
- ?>
- <?php }
- if($display == 'row'){
- echo '</table>' ;
- }
- ?>
- <?php else : ?>
- <?php endif; ?>
- <div class="clear index-space"></div>
- <?php
- wp_simple_pagination(array('base' => 'store/products'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement