Wordpress裁剪了RSS Feed的缩略图

时间:2014-06-03 22:39:59

标签: wordpress

我正在使用以下内容在WordPress中为RSS源生成缩略图:

<media:content medium="image" width="128" url="<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>" />

如何使用调整大小的&amp;更换图像?裁剪缩略图方块为128x128px?

1 个答案:

答案 0 :(得分:1)

改为使用wp_get_attachment_image_src

显然你会想要添加一些错误检查,但这将是你的场景下的示例用法:

// wp_get_attachment_image_src requires the attachment id, so get that first
$attachment_id = get_post_thumbnail_id($post->ID);
// define the desired size as an array in the second option
$image_attr = wp_get_attachment_image_src($attachment_id, array(128,128));
// wp_get_attachment_image_src returns an array: 
// [0] = url, [1] = width, [2] = height, [3] = resized (true / false)
// Retrieve the url from the array
$url = $image_attr[0];

// pass the url into your media element
<media:content medium="image" width="128" url="<?php echo $url; ?>" />