我需要为我的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');
}
?>
做模板的东西的方法,但因为每个产品需要定制,这将导致相当多的不必要的类别模板。
有没有一种方法来定位产品ID?
正文css类是不够的。我需要为每个模板。
在这种情况下使用开关会更好吗?默认等价于你的else语句吗?没有功能差异只是更容易阅读和更新。 – Dez 2014-08-28 19:17:01
@Dez为了可读性,可能。我说可能是因为我不确定封装在这个特定情况下有多重要。 IF/Switch语句都以不同的方式处理变量作用域。在Java中也是如此。 – 2014-08-28 19:34:07