如何在woocommerce中为不同类别的存档页面调用不同的模板 [英] How to call different template for different category archive page in woocommerce

查看:75
本文介绍了如何在woocommerce中为不同类别的存档页面调用不同的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在woocommerce中有两个类别,一个是男人",另一个是女人".

I have two categories in woocommerce One is "Men" and Other is "Women".

作为默认的woocommerce调用category-archive页面的archive-product.php.

Be default woocommerce call archive-product.php for category archive page.

但是我想为每个类别存档页面显示不同的布局.

But I want to show different layout for each category archive page.

该怎么做?

推荐答案

只需在这里回答:您需要编辑文件"taxonomy-product_cat.php"并添加条件is_product_category('mycategory').

you need to edit the file "taxonomy-product_cat.php" and add a conditional is_product_category( 'mycategory' ).

  1. 打开您的主题文件夹,并添加一个名为"woocommerce"的新子文件夹.
  2. 将/plugins/woocommerce/templates中的文件"archive-product.php"和"taxonomy-product_cat.php"复制到主题中的woocommerce子文件夹中.
  3. 将"archive-product.php"重命名为"archive-mycategory.php"(或任何您喜欢的名称,这将是该类别的模板文件).
  4. 打开"taxonomy-product_cat.php"并包装wc_get_template('archive-product.php');与:

  1. open your theme folder and add a new subfolder named "woocommerce" to it.
  2. copy the files "archive-product.php" and "taxonomy-product_cat.php" from /plugins/woocommerce/templates to the woocommerce subfolder in your theme.
  3. rename "archive-product.php" to "archive-mycategory.php" (or whatever you like, this will be the template file to the category).
  4. open "taxonomy-product_cat.php" and wrap the wc_get_template( 'archive-product.php' ); with:

如果(is_product_category('mycategory')){ wc_get_template('archive-mycategory.php'); } else {wc_get_template('archive-product.php'); }

if (is_product_category( 'mycategory' )){ wc_get_template( 'archive-mycategory.php' ); } else { wc_get_template( 'archive-product.php' ); }

这篇关于如何在woocommerce中为不同类别的存档页面调用不同的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆