douyi0219
2014-07-24 06:01
浏览 143
已采纳

如何检查页面是否是woocommerce中的类别或产品?

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.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanheye7909 2014-07-24 06:56
    已采纳

    you should use

    is_product_category()
    

    instead of

    is_category()
    
    已采纳该答案
    打赏 评论
  • dongtan7998 2016-07-26 10:06

    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.

    打赏 评论

相关推荐 更多相似问题