我需要为我的woocommerce网站中的每个产品制作单独的模板。
有没有类似于single-product-9455.php
的方法?
我相信我可以使用这样的类别来制作模板
<?php
if ( has_term( 'custom-1', 'product_cat' ) ) {
wc_get_template_part( 'content', 'custom-1' );
}
elseif ( has_term( 'custom-2', 'product_cat' ) ) {
wc_get_template_part( 'content', 'single-product-custom-2' );
}
else {
wc_get_template_part( 'content', 'single-product' );
}
?>
但这将导致相当多的不必要的类别,因为每个产品都需要一个自定义模板。
有什么方法可以锁定产品标识吗?
体css类是不够的。我需要每个人的模板。
发布于 2014-08-28 18:16:10
你可以,但你不想这么做。随着网站的发展,它可能会变得非常混乱。一个明智的方向是使用条件词。
否则,如果兔子洞听起来不错,你可能想要为每个产品创建一个新的类别来挂钩一个条件.
1)如果主题目录不存在,则在主题目录中创建woocommerce文件夹。
2)在这个名为"woocommerce“的目录中,复制您的内容-单产品. the文件,并命名新的content-single-product-TEMPLATENAME.php文件。
还将woocommerce模板文件single-product.php从woocommerce复制到名为woocommerce的目录中,并找到折叠行:
3)在您刚刚复制的single-product.php中找到下面一行。
woocommerce_get_template_part( 'content', 'single-product' );
将此更改为:
if (is_product_category( '1CATEGORY') // Where this is the category name
{
// Category name 1
woocommerce_get_template_part( 'content', 'single-product-TEMPLATENAME' );
}
elseif (is_product_category( '2CATEGORYNAME')
{
// category name 2
woocommerce_get_template_part( 'content', 'single-product-TEMPALTENAME2' );
}
else
{
// You will allows want to default to the single product template.
woocommerce_get_template_part( 'content', 'single-product' );
} //endif
如果有一种方法可以从产品id挂钩,您可能不想这样做。这将要求产品提前到位,从开发/业务的角度来看,这是毫无意义的。
欢迎修订。
https://stackoverflow.com/questions/25555151
复制相似问题