How to check if a page is category or product in w

2019-02-12 20:05发布

问题:

I'm trying to use is_category in woocommerce.php which is not working. I want to print the title according the page.

IF a page is category page then will print woocommerce_page_title() and if a page is product then should print the_title().

And the code I am using in woocommerce.php is:

<?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.

Or Can any one tell how woocommerce do it to print category and product title?

Any help will be appreciated.

回答1:

you should use

is_product_category()

instead of

is_category()


回答2:

Try creating a archive-product.php file within the theme templates.

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.