Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 如果产品上的特色图片是[图片url],请做些什么_Wordpress_Woocommerce - Fatal编程技术网

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;
}