在Woocommerce中将HTML属性或img标题添加到缩略图

时间:2018-08-03 19:57:04

标签: php wordpress woocommerce image-gallery

我正在尝试在产品库中的网站上为img元素添加属性。我希望它与样本选择的数据值匹配。

这是我正在使用的网站:https://www.blawsomes.com/producto/trachelium-2/

我希望img元素具有数据值或至少标题,现在它仅具有img src。 我尝试使用PHP中的某些功能,但没有成功。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

如果使用get_the_post_thumbnail()https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/,则传递的第三个变量是属性数组。因此,如果您可以在模板中修改通话

the_post_thumbnail();

echo get_the_post_thumbnail($post_id,'thumbnail',array('data-value' => 'the value you want here'));

或更简单地

the_post_thumbnail('thumbnail',array('data-value' => 'the value you want here'));

那应该让你接近。请注意,$ post_id必须是您想要的图像的帖子。因此,如果它是循环的一部分,请不要使用全局post_id。

相关问题