【问题标题】:Creating a different template file for certain Product Categories - Wordpress/Woocommerce?为某些产品类别创建不同的模板文件 - Wordpress/Woocommerce?
【发布时间】:2015-12-10 18:15:27
【问题描述】:

我正在尝试根据某个 Woocommerce 产品所在的类别制作不同的模板文件。

我一直在谷歌上寻找解决方案。我尝试创建一个名为“taxonomy-product_cat-[slugnamehere].php”的模板,但没有成功。我尝试制作模板文件,然后使用 if/else 语句在 single_product.php 中设置模板文件。它也不起作用。

我的产品类别称为“盒子”。下面是来自 single_product 的代码;它似乎不起作用。任何建议将不胜感激:

} else if ( is_product_category() ) {
            if ( is_product_category( 'box' ) ) {
                woocommerce_get_template_part( 'content', 'single-product-sample-box-4');
            }               
        }
        else {
            woocommerce_get_template_part( 'content', 'single-product');
        }

如果选择了“盒子”类别,我希望显示 content-single-product-sample-box-4 模板 - 而不是只显示 content-single-product 模板。

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    我找到了答案!对于其他为此苦苦挣扎的人,我将发布我的解决方案...我只是想更改一个产品的模板(它是一个样品盒,因此与所有其他项目不同)。

    而不是这个:

    } else if ( is_product_category() ) {
            if ( is_product_category( 'box' ) ) {
                woocommerce_get_template_part( 'content', 'single-product-sample-box-4');
            }               
        }
        else {
            woocommerce_get_template_part( 'content', 'single-product');
        }
    

    我这样做了:

    } else if ( get_the_ID() == [PAGE ID GOES HERE] ) {
                woocommerce_get_template_part( 'content', 'single-product-sample-box-4');
    
            }
            else {
                woocommerce_get_template_part( 'content', 'single-product');
            }
    

    【讨论】:

      猜你喜欢
      • 2019-04-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 2014-01-27
      • 2021-01-09
      相关资源
      最近更新 更多