Advertisement
Guest User

Untitled

a guest
Mar 5th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.01 KB | None | 0 0
  1. function mp_display_products($query = '', $display){
  2.  
  3.     wp_reset_query();
  4.  
  5.     //$new_query_wp = new WP_Query($query) ;
  6.     $new_query = query_posts($query) ;
  7.  
  8.  
  9.     wp_simple_pagination(/*array('base' => 'store/products')*/);   
  10.  
  11.     $i = 1 ;
  12.  
  13.     if($display == 'row'){
  14.         echo '<table summary="Display featured products in rows" id="products-list">' ;
  15.     }
  16.  
  17.     if ( $new_query != '' ) : ?>
  18.  
  19.         <?php /* Start the Loop */ ?>
  20.         <?php foreach ($new_query as $post) {
  21.        
  22.                 $sale_price = get_post_meta($post->ID, 'mp_sale_price', true) ;
  23.                 $sale_price = $sale_price[0] ;
  24.                 $price = get_post_meta($post->ID, 'mp_price', true) ;
  25.                
  26.                 //Determines end_price
  27.                 if($sale_price == 0){
  28.  
  29.                     //End price is normal price
  30.                     $end_price = '$'.$price[0] ;
  31.  
  32.                 }
  33.                 else{
  34.  
  35.                     //Or end price is  sale price
  36.                     $end_price = '$'.$sale_price ;
  37.                 }
  38.                 //If theres a sale price
  39.                 if($sale_price != 0){
  40.                    
  41.                     //We display
  42.                     $price = 'RRP: <span class="price">$'.$price[0].'</span>' ;
  43.                    
  44.                 }
  45.                 else{
  46.  
  47.                     //Or we don't
  48.                     $price = "" ;
  49.                 }
  50.             ?>
  51.             <?php //We display each product
  52.  
  53.             //Let's shorten the title string
  54.             $title = $post->post_title ;
  55.             $string_size = 25 ;
  56.  
  57.             //Test if string is longer that string_size
  58.             if(strlen($title) > $string_size){
  59.  
  60.                 $title = substr($title, 0, $string_size).'...' ;
  61.  
  62.             }
  63.  
  64.             //Check if we need a grid of a row display
  65.             if($display == 'grid'){
  66.  
  67.     //Inventory
  68.     $inventory = get_post_meta($post->ID, 'mp_inventory', true) ;
  69.  
  70.             ?>
  71.         <article class="post-<?php echo $post->ID ; ?> product post-product-<?php echo $i ; ?>">
  72.             <h2><a href="<?php echo get_permalink( $post->ID ) ; ?>" title="View product: <?php echo $post->post_title ; ?>"><?php echo $title ; ?></a></h2>
  73.            
  74.             <?php //Test if there is a thumbnail
  75.             if(has_post_thumbnail($post->ID)){
  76.                
  77.                 echo '<div class="image_product">' ;
  78.                 mp_product_image( $echo = true, $context = 'list', $post->ID, $size = 200 ) ;
  79.                 echo '</div><!--end thumbnail-->' ;
  80.            
  81.             }
  82.             else{
  83.            
  84.                 echo '<div class="image_product">
  85.                 <img src="'.get_template_directory_uri().'/images/default-product.png" alt="Default image for product" />
  86.                 </div>' ;
  87.            
  88.             }
  89.             ?>
  90.             <div class="product-details">
  91.            
  92.                 <span class="product-old-price"><?php echo $price ; ?></span>
  93.                 <span class="product-detail-link"><a href="<?php echo get_permalink($post->ID) ; ?>">Details</a></span>
  94.                 <span class="product-price"><?php echo $end_price ; ?></span>
  95.             <?php
  96.  
  97.             //If inventory isn't empty
  98.             if(!empty($inventory)){
  99.                 mp_buy_button( $echo = true, $context = 'list', $post_id = $post->ID ) ;
  100.             }
  101.  
  102.                 ?>
  103.             </div> 
  104.         </article>
  105.            
  106.             <?php
  107.  
  108.             }//end grid display
  109.             //Start row
  110.             else{
  111.  
  112.                 echo '<tr>
  113.  
  114.                     <td>' ;
  115.                     if(has_post_thumbnail($post->ID)){
  116.                
  117.                         echo '<div class="image_product">' ;
  118.                         mp_product_image( $echo = true, $context = 'list', $post->ID, $size = 88 ) ;
  119.                         echo '</div><!--end thumbnail-->' ;
  120.                    
  121.                     }
  122.                     else{
  123.                    
  124.                         echo '<div class="image_product">
  125.                         <img src="'.get_template_directory_uri().'/images/default-product.png" alt="Default image for product" />
  126.                         </div>' ;
  127.                    
  128.                     }
  129.  
  130.                 echo '</td>
  131.                     <td class="title"><h2><a href="'.get_permalink( $post->ID ).'" title="View product: '.$post->post_title.'">'.$post->post_title.'</a></h2>
  132.                     <span class="product-detail-link"><a href="'.get_permalink( $post->ID ).'">Details</a></span></td>
  133.                     <td>Customer Rating:' ;
  134.                     if(function_exists('kk_star_ratings')) : echo kk_star_ratings($post->ID); endif;
  135.  
  136.                 $comments_count = wp_count_comments( $post->ID );
  137.  
  138.                 echo '<span class="reviews">Reviews ('.$comments_count->approved.')</span></td>
  139.                     <td class="price"><span class="product-price">'.$end_price.'</span>';
  140.                     mp_buy_button( $echo = true, $context = 'list', $post_id = $post->ID ) ;
  141.                 echo '</td></tr>' ;
  142.  
  143.             }
  144.  
  145.  
  146.             $i++ ;
  147.            
  148.             if($i == 4){ $i = 1 ; }
  149.            
  150.             ?> 
  151.         <?php }
  152.             if($display == 'row'){
  153.             echo '</table>' ;
  154.         }
  155.         ?>
  156.     <?php else : ?>
  157.     <?php endif; ?>
  158.  
  159.     <div class="clear index-space"></div>
  160.     <?php
  161.     wp_simple_pagination(array('base' => 'store/products'));
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement