php 如何在woocommerce中检查页面是类别还是产品?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24926164/
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
How to check if a page is category or product in woocommerce?
提问by user3777827
I'm trying to use is_category in woocommerce.php
which is not working. I want to print the title according the page.
我正在尝试使用woocommerce.php
无法正常工作的is_category 。我想根据页面打印标题。
IF a page is category page then will print woocommerce_page_title()
and if a page is product then should print the_title()
.
如果页面是类别页面,则将打印woocommerce_page_title()
,如果页面是产品,则应打印the_title()
。
And the code I am using in woocommerce.php
is:
我使用的代码woocommerce.php
是:
<?php if(is_category()){ ?>
<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
<?php }
else{
the_title();
}
?>
But in every case it is printing the_title()
. I think is_category()
is not working for woocommerce.
但在任何情况下它都是打印the_title()
。我认为is_category()
不适用于 woocommerce。
Or Can any one tell how woocommerce do it to print category and product title?
或者谁能告诉 woocommerce 如何打印类别和产品标题?
Any help will be appreciated.
任何帮助将不胜感激。
回答by Shah Rukh
you should use
你应该使用
is_product_category()
instead of
代替
is_category()
回答by Mayur
Try creating a archive-product.php
file within the theme templates.
尝试archive-product.php
在主题模板中创建一个文件。
I usually copy the one that is in the woocommerce
folder and add a span with "test" text to the one I create so I can see it's working.
我通常复制woocommerce
文件夹中的那个,然后在我创建的那个中添加一个带有“测试”文本的跨度,这样我就可以看到它正在工作。