WooCommerce:更改单个产品页面的模板
-
-
您在编辑页面屏幕上看到的下拉菜单仅适用于页面.可能重复的问题: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
-
[您可能对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 个回答
- 投票数
-
- 2015-06-03
Woo Commerce作为插件是不重要的,与WordPress无关,但是您可以做的是将single-product.php模板复制到子主题中的WooCommerce文件夹中.更改文件名并修改文件,然后使用
single_template
或template_include
.单模板
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; }
-
这些都不能完全回答以下问题:"如何更改特定产品页面的模板文件?"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
您需要检查WordPress 模板层次结构的工作原理.
单个帖子#
单个帖子模板文件用于呈现单个帖子. WordPress使用以下路径:
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是WordPress专用的,并使用以下修补程序:
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
对于特定ID,您可以使用
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.
我知道可以通过在子主题中编辑文件
single-product-php
-来更改产品页面的结构/设计.对该文件所做的更改将影响所有产品页面.
但是如何更改特定产品页面的模板文件?就像我可以使用自定义页面模板一样吗?从头开始,在单个产品页面上没有模板下拉菜单,就像页面(图像)一样.
如何更改特定产品页面的模板?