Advertisement
Guest User

wp e-commerce multi image for 3.8+

a guest
May 16th, 2011
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2. /*Call the Extra Thumbails */
  3.  
  4. function makethumburl($url, $delete = false){
  5.     //This function has 2 uses: 1. to rejig the image url to call the thumbnail sized version of the image. 2. The remove the file extension so the image can be compared to the thumbail already called.
  6.     $exts = array('.jpg','.jpeg','.png','.gif');
  7.    
  8.     foreach($exts as $ext){
  9.     if(strpos($url,$ext)){
  10.         $theext = $ext;
  11.         }
  12.     }
  13.     if ($delete == true ) {$replacer = '';} else {$replacer = '-38x38' . $theext;}
  14.    
  15.     return substr_replace($url, $replacer, (strlen($theext)*-1), strlen($theext));
  16. }
  17.  
  18. $i=1;
  19. //We now query the database directly to obtain the attached images.
  20. $query = 'SELECT *
  21. FROM `wp_posts`
  22. WHERE `post_parent` = "' . wpsc_the_product_id() .'"  
  23. AND `post_type` = "attachment"';
  24.  
  25. $result = mysql_query($query);
  26. while($row = mysql_fetch_array($result)){
  27.  
  28. $image_url = $row['guid'];
  29.  
  30. if ( strpos(wpsc_the_product_image(), makethumburl($image_url, true)) === false ) //Checks if the image has already been called earlier as product thumbnail.
  31.         {
  32.         ?>
  33.         <a href="<?php echo $image_url; ?>" rel="lightbox[<?php echo wpsc_the_product_id(); ?>]">
  34.         <img src="<?php echo makethumburl($image_url); ?>" width="36px" height="36px" alt="<?php echo wpsc_the_product_title() . ' ' . $i; ?>"/>
  35.         </a>
  36.         <?php
  37.         $i++;
  38.         }
  39. }
  40. /*END - Call the Extra Thumbails */
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement