【问题标题】:Wordpress: Using the_post_thumbnail() for custom field imageWordpress:使用 the_post_thumbnail() 自定义字段图像
【发布时间】:2012-11-20 11:56:05
【问题描述】:

我使用自定义字段photo 上传图片。在前端,我使用以下代码获取其 URL:

$imgid=get_post_meta($post->ID, 'photo', true);
$img=wp_get_attachment_image_src($imgid);
$imgurl=$img[0];

现在我想使用 the_post_thumbnail() 的标准 WP 尺寸(缩略图、中号、...)来显示它。

我尝试了一些不起作用的解决方案:

the_post_thumbnail('medium', array('src' => $imgurl));

the_post_thumbnail('medium', $img);

有什么想法吗?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    只需将大小作为wp_get_attachment_image_src() 的第二个参数传递,如下所示:

    $imgid = get_post_meta($post->ID, 'photo', true);
    $img = wp_get_attachment_image_src( $imgid, 'thumbnail' );
    $imgurl = $img[0];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多