【问题标题】:I'm developing a wordpress theme and using custom fields. I've got the following code:我正在开发一个 wordpress 主题并使用自定义字段。我有以下代码:
【发布时间】:2013-05-09 14:34:08
【问题描述】:
<img src="<?php echo get_post_meta($post->ID, 'thumbnail', true);?>" alt="Post Pic" width="615" height="275" /></a>

该代码给出了这个:

<img src="" alt="Post Pic" width="615" height="275">

关于为什么图像无法正确显示的任何想法?

【问题讨论】:

  • 这个 wordpress 相关吗?
  • 图片不会显示在帖子或缩略图中............我正在使用特色图片

标签: image wordpress templates post thumbnails


【解决方案1】:

显示帖子特色图片的正确方法是使用the_post_thumbnail()&lt;img&gt; 标记回显到您的页面,或使用get_the_post_thumbnail() 将结果作为字符串返回。您不应该直接使用自定义/元字段。

【讨论】:

    【解决方案2】:

    主要原因是元字段缩略图未填充。如果你想显示帖子的缩略图,你可以使用函数get_the_post_thumbnail()

    <?php echo get_the_post_thumbnail($post->ID, 'thumbnail'); ?>
    

    如果您只想填充img 标记的src,也可以尝试以下代码

    <img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($item->ID)); ?>" alt="Post Pic" width="615" height="275" /></a>
    

    【讨论】:

      猜你喜欢
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多