我需要爲我的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