Wordpress 如果产品上的特色图片是[图片url],请做些什么
如果产品上的特色图像是Wordpress 如果产品上的特色图片是[图片url],请做些什么,wordpress,woocommerce,Wordpress,Woocommerce,如果产品上的特色图像是/wp content/uploads/2014/05/test.jpg,如何在图像标签上添加CSS 例如,如果特征图像是/wp content/uploads/2014/05/test.jpg,它将如下所示: <img src="/wp-content/uploads/2014/05/test.jpg" style="width: 100px"> 我怎样才能做到这一点?对于最简单的情况,您需要编辑要进行此更改的post缩略图代码(显然在循环中) if
/wp content/uploads/2014/05/test.jpg
,如何在图像标签上添加CSS
例如,如果特征图像是/wp content/uploads/2014/05/test.jpg
,它将如下所示:
<img src="/wp-content/uploads/2014/05/test.jpg" style="width: 100px">
我怎样才能做到这一点?对于最简单的情况,您需要编辑要进行此更改的post缩略图代码(显然在循环中)
if ( has_post_thumbnail() ) {
$image_link = wp_get_attachment_image_src( get_post_thumbnail_id() );
$your_test_image_link = ''; // this is the full url to the test image
if( $image_link == $your_test_image_link ){
echo '<img src="'.$image_link.'" style="width:100px">';
}
else{
the_post_thumbnail();
}
}
Yiedpozi,请阅读感谢您提供的信息。:)
add_filter('wp_get_attachment_image_attributes','23825701_custom_wp_get_attachment_image_attributes');
function 23825701_custom_wp_get_attachment_image_attributes($attr, $attachment){
$image_link = wp_get_attachment_image_src( $attachment );
$your_test_image_link = ''; // this is the full url to the test image
if( $image_link == $your_test_image_link ){
$attr['style'] = 'width:100px'; // your custom attribute, hence style
return $attr;
}
return $attr;
}