Wordpress获得完整图像的src

时间:2015-02-03 09:16:40

标签: wordpress wordpress-theming

当我尝试获取全尺寸图像src时。 url的功能:

$image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'full' );

我注意到了:

Notice: Undefined index: full in F:\wamp\www\igniter\wp-includes\media.php on line 71

返回有关该文件的信息(网址和尺寸),但附有此通知。

当我添加这样的自定义图像尺寸时,问题在于函数image_constrain_size_for_editor:

'custom' => array(
// add image for all post type
   array(
        'width'  => 263, // (1/4 grid)
        'height' => 133,
        'crop'   => true,
    ),
    'masonry' => array(
        'width'  => 360,
        'height' => 1000,
        'crop'   => false,
    ),

在文件media.php第70行是:

} elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {

in_array函数应该具有true的严格参数。 现在我将自定义图像数组更改为:

'custom' => array(
        // add image for all post type
        'grid-1/4' => array(
            'width'  => 263, // (1/4 grid)
            'height' => 133,
            'crop'   => true,
        ),
        'masonry' => array(
            'width'  => 360,
            'height' => 1000,
            'crop'   => false,
        ),
    )

1 个答案:

答案 0 :(得分:0)

使用

wp_get_attachment_image( $attachment->ID, 'full' );

而不是

wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'full' );

Refrence