[英]Add custom html tag around category images in woocommerce category archive pages
I have a shop page that is showing at the top the product categories and then it starts showing the products. 我有一个商店页面,该页面在顶部显示产品类别,然后开始显示产品。
For the product categories thumbs I added a zoom in effect when hover in the img. 对于产品类别,当鼠标悬停在img中时,我添加了放大效果。
But i need to wrap that image in a div to set a height and width so i can overflow:hidden; 但是我需要将该图像包装在div中以设置高度和宽度,以便我可以溢出:hidden; the rest of the image i dont want to show on hover.
我不想在悬停时显示的其余图像。
I've been trying to find the loop in the archives but i dont find it. 我一直在尝试在档案中找到循环,但找不到。
Does someone knows where i can find that? 有人知道我在哪里可以找到吗?
Thanks! 谢谢!
What I need is to wrap the images of each sub category in a div 我需要的是将每个子类别的图像包装在div中
https://www.evernote.com/shard/s423/sh/22d92a4c-ca26-4dae-9c09-ed15dc833fb1/f0c2b1b7b7f7bac0c513e5bd9534bcdb https://www.evernote.com/shard/s423/sh/22d92a4c-ca26-4dae-9c09-ed15dc833fb1/f0c2b1b7b7f7bac0c513e5bd9534bcdb
So you could override the template content-product_cat.php
(where the category image is hooked) and add your opening tag before line 32 and the closing tag after line 37 around this: 因此,您可以覆盖模板
content-product_cat.php
(挂接类别图像的模板),并在第32行之前添加开始标记,在第37行之后添加结束标记:
/**
* woocommerce_before_subcategory_title hook.
*
* @hooked woocommerce_subcategory_thumbnail - 10
*/
do_action( 'woocommerce_before_subcategory_title', $category );
But instead you can use the existing hook
woocommerce_before_subcategory_title
(line 37) , where the image is hooked (or called), to wrap the image in some html tag of your choice, so you can try this:但是,相反,您可以使用现有的钩子
woocommerce_before_subcategory_title
(第37行) (该钩子(或调用了该图像))将图像包装在您选择的某些html标签中,因此可以尝试以下操作:
add_action( 'woocommerce_before_subcategory_title', function( $category ){
// The opening div (priority 8)
echo '<div class="some-class">';
}, 8, 1);
add_action( 'woocommerce_before_subcategory_title', function( $category ){
// The closing div (priority 12)
echo '</div>';
}, 12, 1);
Code goes in function.php file of your active child theme (or theme) or also in any plugin file. 代码在您的活动子主题(或主题)的function.php文件中,或者在任何插件文件中。
This last way is the best one. 最后一种方法是最好的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.