【问题标题】:Wordpress get src of full imageWordpress 获取完整图像的 src
【发布时间】:2015-02-03 09:16:39
【问题描述】:

当我尝试获取全尺寸图片 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

返回有关文件的信息(url 和大小),但带有此通知。

当我像这样添加自定义图像大小时,问题出在函数 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 函数应该有严格的参数为真。 现在我将自定义图像数组更改为:

'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,
        ),
    )

【问题讨论】:

    标签: wordpress wordpress-theming


    【解决方案1】:

    使用

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

    而不是

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

    Refrence

    【讨论】:

    • 不,这不起作用。问题是当我像这样添加具有自定义图像大小的数组时:'custom' => array( // 为所有帖子类型数组添加图像( 'width' => 263, // (1/4 grid) 'height' = > 133, 'crop' => true, ), 'masonry' => array( 'width' => 360, ..... ), ) 错误在函数 image_constrain_size_for_editor 第 70 行: in_array( $size, array_keys( $ _wp_additional_image_sizes ) ) 应该是:in_array( $size, array_keys( $_wp_additional_image_sizes ), true )
    猜你喜欢
    • 2010-11-12
    • 2014-08-17
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    • 2012-10-16
    • 2021-07-14
    • 2013-04-06
    相关资源
    最近更新 更多