简体   繁体   English

WooCommerce产品类别自定义图片

[英]WooCommerce product category custom image

I've been digging and digging, but I'm not finding the answers I need on this. 我一直在挖掘,但是我没有找到需要的答案。 I currently am using WordPress - Woocommerce, a purchased theme called Shopifiq. 我目前正在使用WordPress-Woocommerce,这是一个名为Shopifiq的购买主题。

I want to display a different banner on each product category page. 我想在每个产品类别页面上显示不同的横幅。 The only thing I can think of is adding something like: 我唯一能想到的就是添加如下内容:

if ( is_product_category( '#' ) ) {
    echo do_something(); //display category thumbnail 
}

in maybe the functions.php file, but I'm not too familiar with PHP and I'm struggling. 可能是在functions.php文件中,但是我对PHP不太熟悉并且正在挣扎。 Any help would be super appreciated! 任何帮助将不胜感激!

  • edit 编辑

I should have mentioned I want the banner to replace the blue bar across the top, which is handles in page_titles.php. 我应该提到我希望横幅广告替换顶部的蓝色栏,它是page_titles.php中的句柄。 I installed a plugin that will display banners on product category pages if anyone is looking - http://wpbackoffice.com/plugins/woocommerce-category-banner/ 我安装了一个插件,如果有人在看的话,它将在产品类别页面上显示横幅-http: //wpbackoffice.com/plugins/woocommerce-category-banner/

But I want it to replace the blue title bar, not just show on the page. 但我希望它代替蓝色标题栏,而不仅仅是在页面上显示。

Here's a category page of mine right now: http://dev.arnoldsofficefurniture.com/product-category/conference/ 现在是我的类别页面: http : //dev.arnoldsofficefurniture.com/product-category/conference/

The logic should be something like: 逻辑应类似于:

  • if product category, then div class="slider single page" should display a background of the product category banner. 如果是产品类别,则div class =“ slider single page”应该显示产品类别横幅的背景。

not sure how your folder structure is setup in your purchased theme, but if you have Woocommerce installed already go to your woocommerce plugin (in the plugins folder) and inside that folder copy all the files under the folder directory called "templates" and place them in the root of your Shopifiq theme in a new folder directory that you're going name "woocommerce". 不知道如何在购买的主题中设置文件夹结构,但是如果已经安装了Woocommerce,请转到woocommerce插件(在plugins文件夹中),然后在该文件夹内复制名为“ templates”的文件夹目录下的所有文件并将其放置您要在Shopifiq主题的根目录中的新文件夹目录中将其命名为“ woocommerce”。 Inside this folder you're going to see a php file called taxonomy-product_cat.php. 在此文件夹中,您将看到一个名为taxonomy-product_cat.php的php文件。 This is the main landing page for your woocommerce categories. 这是您的woocommerce类别的主要登录页面。 Place your conditional statement here. 将您的条件语句放在这里。

if (is_product_category( 'shirts' )) { echo "whatever html/php you want to show up";  }

Push all files to your server and you should be good to go now. 将所有文件推送到您的服务器,现在应该可以了。

After digging in the PHP files, I gave up and tried what I know best as a front-end developer - CSS. 深入研究PHP文件后,我放弃了尝试并尝试了作为前端开发人员最了解的CSS。 This is not ideal since it will need to be manually updated in the CSS whenever you want to change it, but it's a work around and seems to be functional! 这是不理想的,因为每当您要更改它时都需要在CSS中对其进行手动更新,但这是可以解决的,并且似乎可以正常工作!

Each product category page has a unique body class. 每个产品类别页面都有一个唯一的正文类别。 In my case the class terms that were unique were term-conference and term-11 , which I targeted in the CSS. 在我的案例中,唯一的类术语是term-conferenceterm-11 ,它们是我在CSS中定位的。 So it wound up like this: 因此它像这样结束:

body.archive.tax-product_cat.term-conference.term-11.woocommerce.woocommerce-page div.slider.single-page {
 background: rgba(0, 0, 0, 0) url("/wp-content/uploads/2015/04/conference_banner.jpg") no-repeat scroll center bottom / cover !important;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM