【问题标题】:Removing The IMG SRC tag in Wordpress删除 Wordpress 中的 IMG SRC 标签
【发布时间】:2015-06-03 13:03:22
【问题描述】:

我正在尝试从 php 中删除“img src”标签,因此它只会显示图像 url,而不是显示实际图像。这是我到目前为止得到的代码,它运行良好,但是当它被渲染时,它显示的是缩略图而不是 url。

<?php $pics = get_post_meta( $post->ID, 'pics', true ); 
    foreach( $pics as $pics) 
    {
        $image_attributes = wp_get_attachment_image_src( $pics['pictures'] );
        echo '<img src="' . $image_attributes[0] . '" />';
    }
?>

我知道有办法做到这一点,但我不知道如何在不破坏图像代码的情况下删除标签。任何帮助表示赞赏。

【问题讨论】:

  • 你能做var_dump($image_attributes); 并向我们展示输出吗?
  • 你为什么不简单地使用 echo $image_attributes[0];
  • $image_attributes[0] 工作,谢谢 Ash。我知道这似乎有点菜鸟,但我只是学习 PHP 大声笑。非常感谢大家的帮助。

标签: php html


【解决方案1】:

如果你只是想echo 图像源而不将其显示为图像然后更改

echo '<img src="' . $image_attributes[0] . '" />';

 echo $image_attributes[0];

<?php 

    $pics = get_post_meta( $post->ID, 'pics', true ); 
    foreach( $pics as $pics) 
    {
        $image_attributes = wp_get_attachment_image_src( $pics['pictures'] );
        echo $image_attributes[0];
    }

?>

【讨论】:

    【解决方案2】:

    那么你想在页面上显示带有标签和src属性的“html代码”吗?

    您是否尝试将“img”标签包含在“pre”标签中?

    echo '<pre><img src="' . $image_attributes[0] . '" /></pre>';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-24
      • 1970-01-01
      • 2016-12-06
      • 2018-11-25
      • 2014-08-31
      • 1970-01-01
      相关资源
      最近更新 更多