How to call different template for different category archive page in woocommerce

陌路散爱 提交于 2019-12-22 12:31:46

问题


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

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

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

How to do this?


回答1:


You can see how WooCommerce is filtering template_include and will automatically look for taxonomy templates in the following order

taxonomy-YOUR_TAXONOMY-YOUR_TERM.php

then

taxonomy-YOUR_TAXONOMY.php

So in your example I believe you would create the following templates:

taxonomy-product_cat-men.php

and

taxonomy-product_cat-women.php




回答2:


Just answered this here: changes-on-archive-product-php-doesnt-work

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

  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:

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




回答3:


You should create different templates for different categories and then use them.

Have a look at here - https://wordpress.stackexchange.com/questions/95386/woocommerce-specific-template-for-product-category



来源:https://stackoverflow.com/questions/24904392/how-to-call-different-template-for-different-category-archive-page-in-woocommerc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!