Forcé de constater que WP e-Commerce ne prend pas en charge plusieurs images sur une page produit, sauf si vous payez pour l’option « Gold Cart », et après quelques jours de recherche acharné sur Google, j’ai enfin trouvé sur le blog de Simon Battersby le bon bout de code qui va bien !
Comment mettre en place le Multiple images pour WP e-Commerce
Voici comment :
Il a remplacé ce code sur la page wpsc-single_product.php
:
[pastacode manual= »%3C%3Fphp%20if%20(%20wpsc_the_product_thumbnail()%20)%20%3A%20%3F%3E%0D%0A%20%20%20%20%20%20%3Ca%20rel%3D%22%3C%3Fphp%20echo%20wpsc_the_product_title()%3B%20%3F%3E%22%20class%3D%22%3C%3Fphp%20echo%20wpsc_the_product_image_link_classes()%3B%20%3F%3E%22%20href%3D%22%3C%3Fphp%20echo%20wpsc_the_product_image()%3B%20%3F%3E%22%3E%0D%0A%20%20%20%20%20%20%20%20%20%3Cimg%20class%3D%22product_image%22%20id%3D%22product_image_%3C%3Fphp%20echo%20wpsc_the_product_id()%3B%20%3F%3E%22%20alt%3D%22%3C%3Fphp%20echo%20wpsc_the_product_title()%3B%20%3F%3E%22%20title%3D%22%3C%3Fphp%20echo%20wpsc_the_product_title()%3B%20%3F%3E%22%20src%3D%22%3C%3Fphp%20echo%20wpsc_the_product_thumbnail(get_option(‘product_image_width’)%2Cget_option(‘product_image_height’)%2C »%2C’single’)%3B%20%3F%3E%22%2F%3E%0D%0A%20%20%20%20%20%20%3C%2Fa%3E%0D%0A%20%20%20%20%20%20%3C%3Fphp%20if%20(%20function_exists(%20’gold_shpcrt_display_gallery’%20)%20)%0D%0A%20%20%20%20%20%20%20%20%20echo%20gold_shpcrt_display_gallery(%20wpsc_the_product_id()%20)%3B%0D%0A%20%20%20%20%20%20%3F%3E%0D%0A%3C%3Fphp%20else%3A%20%3F%3E » provider= »manual » lang= »php »/]
Par ce code :
[pastacode manual= »%3C%3Fphp%20if%20(%20wpsc_the_product_thumbnail())%20%3A%2F%2Fif%20the%20product%20has%20any%20images…%0D%0A%20%20%20%20%20%20if%20(has_post_thumbnail())%3A%20%2F%2F…display%20the%20thumbnail%20if%20there%20is%20one…%20%3F%3E%0D%0A%20%20%20%20%20%20%20%20%20%3Ca%20rel%3D%22lightbox%5B%3C%3Fphp%20echo%20wpsc_the_product_title()%3B%20%3F%3E%5D%22%20class%3D%22%3C%3Fphp%20echo%20wpsc_the_product_image_link_classes()%3B%20%3F%3E%22%20href%3D%22%3C%3Fphp%20echo%20wpsc_the_product_image()%3B%20%3F%3E%22%3E%0D%0A%20%20%20%20%20%20%20%20%20%3C%3Fphp%20echo%20get_the_post_thumbnail(wpsc_the_product_id()%2C’thumbnail’%2Carray(‘alt’%20%3D%3E%20wpsc_the_product_title()%2C’title’%20%3D%3E%20wpsc_the_product_title()%20))%3B%3F%3E%0D%0A%20%20%20%20%20%20%20%20%20%3C%2Fa%3E%0D%0A%20%20%20%20%20%20%3C%3Fphp%20endif%3B%0D%0A%20%20%20%20%20%20sb_get_images_for_product(wpsc_the_product_id())%3B%2F%2F…and%20then%20display%20all%20the%20rest%20of%20the%20images%0D%0Aelse%3A%20%3F%3E » provider= »manual » lang= »php »/]
Pour que cela fonctionne, il a créé une nouvelle fonction à mettre dans votre functions.php
de votre thème :
[pastacode manual= »function%20sb_get_images_for_product(%24id)%7B%0D%0A%20%20%20global%20%24wpdb%3B%0D%0A%20%20%20%24post_thumbnail%20%3D%20get_post_thumbnail_id()%3B%2F%2Fread%20the%20thumbnail%20id%0D%0A%20%20%20%24attachments%20%3D%20%24wpdb-%3Eget_results(%24wpdb-%3Eprepare(%22SELECT%20*%20FROM%20%24wpdb-%3Eposts%20WHERE%20post_parent%20%3D%20%24id%20AND%20post_type%20%3D%20’attachment’%20ORDER%20BY%20menu_order%20ASC%22))%3B%0D%0A%20%20%20foreach%20(%24attachments%20as%20%24attachment)%7B%0D%0A%20%20%20%20%20%20if%20(%24attachment-%3EID%20%3C%3E%20%24post_thumbnail)%7B%2F%2Fif%20we%20haven’t%20already%20got%20the%20attachment%20as%20the%20post%20thumbnail%0D%0A%20%20%20%20%20%20%20%20%20%24image_attributes%20%3D%20wp_get_attachment_image_src(%24attachment-%3EID%2C’thumbnail’)%3B%3F%3E%0D%0A%09%3Ca%20rel%3D%22lightbox%5B%3C%3Fphp%20echo%20wpsc_the_product_title()%3B%20%3F%3E%5D%22%20href%3D%22%3C%3Fphp%20echo%20%24attachment-%3Eguid%3B%20%3F%3E%22%20class%3D%22%3C%3Fphp%20echo%20wpsc_the_product_image_link_classes()%3B%20%3F%3E%22%3E%0D%0A%09%3Cimg%20src%3D%22%3C%3Fphp%20echo%20%24image_attributes%5B0%5D%3B%20%3F%3E%22%20alt%3D%22%3C%3Fphp%20echo%20wpsc_the_product_title()%3B%20%3F%3E%22%2F%3E%0D%0A%09%3C%2Fa%3E%0D%0A%20%20%20%3C%3Fphp%20%7D%0D%0A%20%20%20%7D%0D%0A%7D » provider= »manual » lang= »php »/]
Pour ma part j’ai déjà modifié cette fonction avec une feuille de style pour afficher les autres miniatures sous l’image principale.
Voilà une astuce pour un Multiple images pour WP e-Commerce que je vous transmet pour vous éviter des heures de recherche.
A bientôt
Bonjour, pour ma part j’ai essayé et quand je vais sur la page du produit, ça me met cette erreur :
Je ne vois pas le code que vous avez rentré mais il est possible qu’il ne fonctionne plus suivant la version de WP e-Commerce. Vous pouvez reposter l’erreur et la version que vous utilisez ? Je testerais du coup de mon côté ensuite.
Super. par contre il faut passer par la modification de fichier via l’éditeur de wordpress, j’ai testé par ftp et ça n’a pas fonctionné.
Merci pour le tuto
C’est bizarre car de mon coté je l’ai utilisé via FTP.