如何将href和img转换为php?

时间:2016-09-13 11:43:47

标签: php wordpress

我有这段代码

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

这个

<a href="/images/preview-kv/1.jpg" data-lightbox="roadtrip"><img src="images/preview-kv/1.jpg" alt=""></a>

我需要使用动态图像将其转换为php ... pls

2 个答案:

答案 0 :(得分:0)

$image是一个数组。

假设$image = array("/images/preview-kv/image1.png","/images/preview-kv/image2.png");

    foreach($image as $image_path)
    {
      ?>
      <!--$image_value is dynamically changed-->        
      <a href="<?php echo $image_path; ?>"   data-lightbox="roadtrip"><img src="<?php echo $image_path; ?>" alt=""></a>
     <?php
    }

答案 1 :(得分:0)

试试这些。我以src中的variable$path = "/images/preview-kv/1.jpg"; $src = "images/preview-kv/1.jpg"; echo '<a href="'.$path.'" data-lightbox="roadtrip"><img src="'.$src.'" alt=""></a>'; 为例

 <a href="<?php echo $path ?>" data-lightbox="roadtrip"><img src="<?php echo $src ?>" alt=""></a>

{{1}}