WooFrance Dépannage et support WordPress WooCommerce › Forums › Les thèmes WordPress WooCommerce › Theme Storefront
- Ce sujet contient 1 réponse, 2 participants et a été mis à jour pour la dernière fois par Guy, le il y a 4 années et 2 mois.
-
AuteurMessages
-
1 septembre 2020 à 11 h 37 min #195211
Bonjour à tous !
Dans mon apprentissage de wordpress – woocomerce je me suis lancé le défis de concevoir un site e-commerce.
J’ai utilisé le théme Storefront, dans la page d’accueil du site je souhaite afficher toutes les catégories de mes produits.
Je suis donc parvenu à les affichers, voici mon code :
<span class="pun"><?</span><span class="pln">php</span> <span class="com">/**</span> <span class="com"> * Template Name: Template Home Page</span> <span class="com"> */</span> <span class="pln">get_header</span><span class="pun">();</span> <span class="pun">?></span> <span class="tag"><div</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"primary"</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"content-area"</span><span class="tag">></span> <span class="tag"><main</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"main"</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"site-main"</span> <span class="atn">role</span><span class="pun">=</span><span class="atv">"main"</span><span class="tag">></span> <span class="pun"><?</span><span class="pln">php</span> <span class="kwd">while</span> <span class="pun">(</span><span class="pln"> have_posts</span><span class="pun">()</span> <span class="pun">)</span> <span class="pun">:</span> <span class="pln"> the_post</span><span class="pun">();</span> <span class="pln"> get_template_part</span><span class="pun">(</span> <span class="str">'content'</span><span class="pun">,</span> <span class="str">'page'</span> <span class="pun">);</span> <span class="pun">?></span> <span class="tag"><section</span> <span class="atn">aria-label</span><span class="pun">=</span><span class="atv">"Catégories de produit"</span><span class="tag">></span> <span class="tag"><h2</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"storefront-product-section-custom-title"</span><span class="tag">></span><span class="pln">Nos catégories</span> <span class="tag"><ul</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"storefront-product-section-custom"</span><span class="tag">></span> <span class="pun"><?</span><span class="pln">php</span> <span class="pln"> $args </span><span class="pun">=</span> <span class="pun">[</span> <span class="com">// Déterminer des informations des catégories des produits $args = array( 'number' => $number,</span> <span class="str">'orderby'</span> <span class="pun">=></span> <span class="str">'slug'</span><span class="pun">,</span> <span class="str">'order'</span> <span class="pun">=></span> <span class="str">'ASC'</span><span class="pun">,</span> <span class="str">'hide_empty'</span> <span class="pun">=></span><span class="pln"> $hide_empty</span><span class="pun">,</span> <span class="str">'include'</span> <span class="pun">=></span><span class="pln"> $ids</span> <span class="pun">];</span> <span class="pln"> $product_categories </span><span class="pun">=</span><span class="pln"> get_terms</span><span class="pun">(</span> <span class="str">'product_cat'</span><span class="pun">,</span><span class="pln"> $args </span><span class="pun">);</span> <span class="com">// Déterminer le nombre de catégories</span> <span class="pln"> $count </span><span class="pun">=</span><span class="pln"> count</span><span class="pun">(</span><span class="pln">$product_categories</span><span class="pun">);</span> <span class="kwd">if</span> <span class="pun">(</span><span class="pln"> $count </span><span class="pun">></span> <span class="lit">0</span> <span class="pun">){</span> <span class="com">// S'il y a au moins une catégorie </span><span class="pun">?><?</span><span class="pln">php</span> <span class="kwd">foreach</span> <span class="pun">(</span><span class="pln">$product_categories </span><span class="kwd">as</span><span class="pln"> $product_category</span><span class="pun">)</span> <span class="pun">{</span> <span class="kwd">if</span><span class="pun">(</span><span class="pln">$product_category</span><span class="pun">-></span><span class="pln">slug </span><span class="pun">!=</span> <span class="str">"non-classe"</span><span class="pun">)</span> <span class="pun">{</span> <span class="com">// Déterminer l'identifiant de la vignette d'une catégorie</span> <span class="pln"> $thumbnail_id </span><span class="pun">=</span><span class="pln"> get_woocommerce_term_meta</span><span class="pun">(</span><span class="pln"> $product_category</span><span class="pun">-></span><span class="pln">term_id</span><span class="pun">,</span> <span class="str">'thumbnail_id'</span><span class="pun">,</span> <span class="kwd">true</span> <span class="pun">);</span> <span class="com">// Extraire l'URL de la vignette</span> <span class="pln"> $thumbnail_url </span><span class="pun">=</span><span class="pln"> wp_get_attachment_thumb_url</span><span class="pun">(</span><span class="pln"> $thumbnail_id </span><span class="pun">);</span> <span class="com">// Aficher la vignette et le nom de la catégorie comme un lien vers la page de la catégorie</span> <span class="pln"> echo </span><span class="str">'</span> <span class="str"> <span class="pun">.</span><span class="pln"> get_term_link</span><span class="pun">(</span><span class="pln"> $product_category </span><span class="pun">)</span> <span class="pun">.</span> <span class="str">'"> </span></span> <span class="str"> <span class="pun">.</span><span class="pln">$thumbnail_url</span><span class="pun">.</span><span class="str">'" width="200px" height="90px" /></span></span> <span class="str"> '</span> <span class="pun">.</span><span class="pln"> $product_category</span><span class="pun">-></span><span class="pln">name </span><span class="pun">.</span> <span class="str">'</span> <span class="str"> '</span><span class="pun">;</span> <span class="pun">}</span> <span class="pun">}</span> <span class="pun">}</span> <span class="pun">?></span> <span class="pun"><?</span><span class="pln">php</span> <span class="pln"> endwhile</span><span class="pun">;</span> <span class="com">// End of the loop.</span> <span class="pun">?></span> <span class="com"><!-- #main --></span><span class="com"><!-- #primary --></span> <span class="pun"><?</span><span class="pln">php</span> <span class="pln">get_footer</span><span class="pun">();</span>J’ai aussi vu qu’il exister la fonction wp_list_categories() !!! mais je comprend pas comment la metre en pratique.
Merci par avance de votre aide.
Bonjour nouveau sur wordpress je me forme.
2 septembre 2020 à 9 h 15 min #195269Bonjour,
As-tu déjà essayé les shortcodes ?
https://docs.woocommerce.com/document/woocommerce-shortcodes/
Content(e) de mon aide ? Vous pouvez m'offrir un café ! 🙂
Avant d'appeler à l'aide: Dépannage Woocommerce
Vous manquez de trafic ? Payez le prix d'un seul backlink et obtenez-en beaucoup plus !
-
AuteurMessages
- Vous devez être connecté pour répondre à ce sujet.