WooCommerce: Changer de modèle pour une seule page de produit
-
-
Cette liste déroulante que vous voyez sur l'écran demodification de lapagen'est disponible quepour lespages.Questionen doublepossible: https://wordpress.stackexchange.com/questions/35221/how-to-get-template-drop-down-menu-in-page-attributes-of-custom-post-type https://stackoverflow.com/questions/5652817/select-template-menu-for-custom-post-typesThat dropdown you see on the edit page screen is only available for pages. Possible duplicate question: https://wordpress.stackexchange.com/questions/35221/how-to-get-template-drop-down-menu-in-page-attributes-of-custom-post-type https://stackoverflow.com/questions/5652817/select-template-menu-for-custom-post-types
- 0
- 2015-06-03
- Jan Beck
-
[Vouspourriez êtreintéressépar laproposition de site WooCommerce!] (Https://area51.stackexchange.com/proposals/80132/woocommerce)[You may be interested in the WooCommerce site proposal!](https://area51.stackexchange.com/proposals/80132/woocommerce)
- 1
- 2015-06-03
- Tom J Nowell
-
2 réponses
- votes
-
- 2015-06-03
Woo Commerceest hors sujet caril s'agit d'unpluginet n'estpas spécifiquement lié à WordPress,mais ce que vouspouvezfaireest de copier lemodèle single-product.php dans un dossier WooCommerce de votrethèmeenfant. changez lenom dufichieret modifiez lefichier,puis utilisez
single_template
outemplate_include
avec labalise conditionnelle correcte.<❯single_template
function get_custom_post_type_template($single_template) { global $post; if ($post->post_type == 'product') { $single_template = dirname( __FILE__ ) . '/single-template.php'; } return $single_template; } add_filter( 'single_template', 'get_custom_post_type_template' );
< template_include
add_filter( 'template_include', 'portfolio_page_template', 99 ); function portfolio_page_template( $template ) { if ( is_page( 'slug' ) ) { $new_template = locate_template( array( 'single-template.php' ) ); if ( '' != $new_template ) { return $new_template ; } } return $template; }
Woo Commerce is off topic as its a plugin and not specifically related to WordPress but what you can do is copy over the single-product.php template to a WooCommerce folder in your child theme. change the file name and modify the file, then use
single_template
ortemplate_include
with the correct conditional tag.single_template
function get_custom_post_type_template($single_template) { global $post; if ($post->post_type == 'product') { $single_template = dirname( __FILE__ ) . '/single-template.php'; } return $single_template; } add_filter( 'single_template', 'get_custom_post_type_template' );
template_include
add_filter( 'template_include', 'portfolio_page_template', 99 ); function portfolio_page_template( $template ) { if ( is_page( 'slug' ) ) { $new_template = locate_template( array( 'single-template.php' ) ); if ( '' != $new_template ) { return $new_template ; } } return $template; }
-
Aucun de ceux-cine répondentièrement à la question,qui était "Commentpuis-jemodifier lefichiermodèlepour despages deproduits spécifiques?"None of these fully answer the question, which was "how do I change the template file for specific product pages?"
- 0
- 2018-11-08
- Chris J Allen
-
- 2015-06-03
Vous devez vérifier la template-hierarchy WordPress comment celafonctionne.
/p>
Numéro d'article unique
Lefichiermodèle depublication uniqueest utilisépour rendre un seulmessage. WordPress utilise le chemin suivant:
1.single-{post-type}.php – First, WordPress looks for a template for the specific post type. For example, post type is product, WordPress would look for single-product.php. 2.single.php – WordPress then falls back to single.php. 3.index.php – Finally, as mentioned above, WordPress ultimately falls back to index.php.
Pagen °
Lefichiermodèle utilisépour rendre unepage statique (post-type depage). Notez que contrairement aux autrestypes depost,lapageest spécialepour WordPresset utilise le correctif suivant:
1. custom template file – The page template assigned to the page. See get_page_templates(). 2. page-{slug}.php – If the page slug is recent-news, WordPress will look to use page-recent-news.php. 3.page-{id}.php – If the page ID is 6, WordPress will look to use page-6.php. 4. page.php 5. index.php
Pour unidentifiant spécifique,vouspouvez utiliser lemodèle
page-{id}.php
.You need to check WordPress template-hierarchy how it works.
Single Post #
The single post template file is used to render a single post. WordPress uses the following path:
1.single-{post-type}.php – First, WordPress looks for a template for the specific post type. For example, post type is product, WordPress would look for single-product.php. 2.single.php – WordPress then falls back to single.php. 3.index.php – Finally, as mentioned above, WordPress ultimately falls back to index.php.
Page #
The template file used to render a static page (page post-type). Note that unlike other post-types, page is special to WordPress and uses the following patch:
1. custom template file – The page template assigned to the page. See get_page_templates(). 2. page-{slug}.php – If the page slug is recent-news, WordPress will look to use page-recent-news.php. 3.page-{id}.php – If the page ID is 6, WordPress will look to use page-6.php. 4. page.php 5. index.php
For specific id you can use
page-{id}.php
template.
Lesmodifications apportées à cefichier affecteronttoutes lespagesproduits.
Mais commentmodifier lefichier demodèlepour despages deproduits spécifiques?Commeje peux avec unmodèle depagepersonnalisé?Àpartir de zéro,iln'y apas de liste déroulante demodèle sur une seulepage deproduit commeil yen apour unepage (l'image).
Comment changer lemodèle d'unepageproduit spécifique?