在Woocommerce中为产品类别归档页面添加正文类 [英] Add a body class for product category archive page in Woocommerce
问题描述
我想在产品类别归档页面的主体类中添加产品类别块.
I want to add product category slug in the body class on product category archive pages.
以下是我想要的示例(产品类别页面示例的网址): https://example.com/product-category/canon/
...所以我想在主体类中使用"canon" .
Here is an example of what I would like (url of the product category page example):
https://example.com/product-category/canon/
… So I would like "canon" in the body class.
推荐答案
您的示例链接似乎无效;但是,WooCommerce应该已经在您的类别页面中添加了特定于术语的类:类似于 archive tax-product_cat term- {slug} term- {id}
到产品类别页面的内容.以您的示例链接为例,并假设术语ID为 7
(例如),主体类将包括:
Your example link doesn't seem to work; however, WooCommerce should already be adding a term-specific class to your category pages: something along the lines of archive tax-product_cat term-{slug} term-{id}
to a product category page. Taking your example link, and assuming the term ID is 7
(for example), the body class would include:
tax-product_cat term-7 term-canon
因此,如果您需要通过CSS/jQuery/其他方式访问它,则可以使用选择器 body.term-canon
.
So if you need to access it via CSS/jQuery/whatever, you can use the selector body.term-canon
.
这篇关于在Woocommerce中为产品类别归档页面添加正文类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!