wordpress 对 archive-product.php 的更改不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16353899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:13:59  来源:igfitidea点击:

Changes on archive-product.php doesn't work

wordpresswoocommerce

提问by Slevin

I'm trying to customize the standard woocommerce theme and so far that has worked well. I copied all template files from /plugins/woocommerce/templatesto /mytheme/woocommerceand customized the files.

我正在尝试自定义标准的 woocommerce 主题,到目前为止效果很好。我从/plugins/woocommerce/templatesto复制了所有模板文件/mytheme/woocommerce并自定义了这些文件。

But when i'm change something in archive-product.phpnothing happens? I even tried to customize this in the core files (/plugins/woocommerce/templates/archive-product.php) but i doesn't work.

但是当我改变时什么都archive-product.php没有发生?我什至尝试在核心文件 ( /plugins/woocommerce/templates/archive-product.php) 中自定义它,但我不起作用。

I want to change the class of the h1heading: <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>.

我想更改h1标题的类:<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>

So i looked up allwoocommerce template files, the class page-titleoccurs only in this one file (to prevent editing the wrong file).

所以我查找了所有woocommerce 模板文件,该类page-title只出现在这个文件中(以防止编辑错误的文件)。

Edit:

编辑:

In detail, i want to customize the theme used in this path: http://example.com/product-category/mycategory

详细来说,我想自定义这个路径中使用的主题:http: //example.com/product-category/mycategory

回答by IAteYourKitten

I tried all the above solutions, to no avail. No matter what I did, the archive-product.php was not being used at all. Instead, most woocommerce pages were using page.php from my theme.

我尝试了上述所有解决方案,但无济于事。无论我做什么,根本没有使用 archive-product.php。相反,大多数 woocommerce 页面都使用我主题中的 page.php。

The solution for me was to add theme support... Which, it's been a while since I used woocommerce, so I completely forgot about that. But after adding the following line to my functions.php file, archive-product.php is now being used (/mytheme/woocommerce/archive-product.php) and I can update it, as I should be able to.

我的解决方案是添加主题支持......其中,我使用woocommerce已经有一段时间了,所以我完全忘记了这一点。但是在向我的functions.php 文件添加以下行之后,现在正在使用archive-product.php (/mytheme/woocommerce/archive-product.php),我可以更新它,因为我应该能够。

add_theme_support('woocommerce');

回答by Talk nerdy to me

Seems this is STILL an issue in Woocommerce. For anyone landing here, the following solution was working for me as of version 2.1.6.

似乎这仍然是 Woocommerce 中的一个问题。对于登陆这里的任何人,从 2.1.6 版开始,以下解决方案对我有用。

Apparently the problem is due to the function woocommerce_content() outputting the wrong page for archive content.

显然,问题是由于函数 woocommerce_content() 为存档内容输出了错误的页面。

I used the following to get around it:

我使用以下方法来解决它:

replace woocommerce_content() in woocommerce.php with:

将 woocommerce.php 中的 woocommerce_content() 替换为:

if ( is_singular( 'product' ) ) {
 woocommerce_content();
}else{
//For ANY product archive.
//Product taxonomy, product search or /shop landing
 woocommerce_get_template( 'archive-product.php' );
}

Credit: found the solution here

信用:在这里找到了解决方案

回答by Van Leo Adrivan

Here's how I fixed mine:

这是我修复我的方法:

  1. Delete woocommerce.php in your theme folder.
  2. Copy TEMPLATE folder in woocommerce plugin dir, paste it in your THEME folder, and rename it to woocommerce.
  3. Open the folder you just renamed, go to shop folder, and edit wrapper-start.php and wrapper-end.php.
  1. 删除主题文件夹中的 woocommerce.php。
  2. 复制 woocommerce 插件目录中的 TEMPLATE 文件夹,将其粘贴到您的 THEME 文件夹中,并将其重命名为 woocommerce。
  3. 打开刚刚重命名的文件夹,进入shop文件夹,编辑wrapper-start.php和wrapper-end.php。

回答by user3806025

If you use the woocommerce.php method you cannot customize archive-product. You must use the hooks method

如果您使用 woocommerce.php 方法,则无法自定义存档产品。您必须使用 hooks 方法

http://docs.woothemes.com/document/third-party-custom-theme-compatibility/Please note: when creating woocommerce.php in your theme's folder, you won't be able to override the woocommerce/archive-product.php custom template as woocommerce.php has the priority over archive-product.php. This is intended to prevent display issues.

http://docs.woothemes.com/document/third-party-custom-theme-compatibility/请注意:在您的主题文件夹中创建 woocommerce.php 时,您将无法覆盖 woocommerce/archive-product。 php 自定义模板作为 woocommerce.php 优先于 archive-product.php。这是为了防止显示问题。

回答by Elad Shoham

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

您需要编辑文件“taxonomy-product_cat.php”并添加条件 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' ); }

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

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

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