【问题标题】:get_post_meta in img src returning srcimg src 中的 get_post_meta 返回 src
【发布时间】:2012-01-05 08:29:59
【问题描述】:

我正在开发一个 wordpress 主题并使用自定义字段。我有以下代码:

<img alt="sunset" src="<?php echo get_post_meta($post_id->ID, 'bottom', true) ?>" height="150" width="450" border="0" />

// That code is giving this:
<img alt="sunset" src="" height="150" width="450" border="0">

我使用此代码检查自定义字段是否为空,它返回正确的图像路径,使用该路径查看图像时正常工作。

<?php exit ( var_dump( get_post_meta($post->ID, 'bottom', true) ) ); ?>

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

【问题讨论】:

    标签: php html wordpress image


    【解决方案1】:

    get_post_meta 返回字段值本身。您可能在字段本身中插入了整个“img”标签。检查你的领域。

    【讨论】:

      【解决方案2】:

      试试这个代码

      <img alt="sunset" src="<?php echo get_post_meta($post->ID, 'bottom', true) ?>" height="150" width="450" border="0" />
      

      我将 $post_id->ID 更改为 $post->ID。谢谢

      【讨论】:

        猜你喜欢
        • 2021-06-29
        • 1970-01-01
        • 2012-11-26
        • 2018-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-04
        • 2010-12-22
        相关资源
        最近更新 更多