如何使用echo在数据图像中添加php代码

时间:2014-03-08 14:51:14

标签: javascript php iframe youtube advanced-custom-fields

我正在使用我的数据来获取iframe src,因为我在function.js中使用了这些数据。

例如,使用此YouTube视频:

我的自定义字段包含youtube id:

<?php the_sub_field('youtube'); ?>

我的缩略图是:

<img src="http://img.youtube.com/vi/<?php the_sub_field('youtube'); ?>/0.jpg" class="photo_medias"/>

和我的iframe:

<iframe width="706" height="364"  src="//www.youtube.com/embed/<?php the_sub_field('youtube'); ?>?showinfo=0&controls=0" frameborder="0" allowfullscreen>

并将其添加到img数据时:

<img src="http://img.youtube.com/vi/<?php the_sub_field('youtube'); ?>/0.jpg"  data-videofull='<iframe width="706" height="364"  src="//www.youtube.com/embed/<?php the_sub_field('youtube'); ?>?showinfo=0&controls=0" frameborder="0" allowfullscreen>"' class="photo_medias">

效果很好。

现在我正在尝试生成另一个数据 - 视频,但使用vimeo代码,生成缩略图并显示它有点不同

这是我的自定义字段,其中包含vimeo id:

<?php the_sub_field('vimeo'); ?>

我的缩略图是(这是有点不同的地方,我需要在里面使用echo)

<?php echo '<img src="' . get_vimeo_thumb(get_sub_field('vimeo'), 'thumbnail_large') . '"" class="photo_medias" >';?>

我的iframe(与youtube相同)

<iframe width="706" height="364"  src="//player.vimeo.com/video/<?php the_sub_field('vimeo'); ?>?title=0" frameborder="0" allowfullscreen></iframe>

但是当尝试将iframe地址添加到data-videofull时,我有一个php错误......

这是我尝试过的,但它不起作用:

<?php echo '<img src="' . get_vimeo_thumb(get_sub_field('vimeo'), 'thumbnail_large') . '"" data-videofull='<iframe width="706" height="364"  src="//player.vimeo.com/video/<?php the_sub_field('vimeo'); ?>?title=0" frameborder="0" allowfullscreen></iframe>' class="photo_medias" >';?>

我想问题来自我的img src的回声,但我必须使用它......

任何人都可以帮我这个吗?

非常感谢你的帮助,

2 个答案:

答案 0 :(得分:1)

有一些问题,你需要转义单引号,也不要将php标签放在php其他标签内,而是连接你的字符串和函数。你还有双引号,我删除了。

<?php echo '<img src="' . get_vimeo_thumb(get_sub_field('vimeo'), 'thumbnail_large') . '" data-videofull=\'<iframe width="706" height="364"  src="//player.vimeo.com/video/'.the_sub_field('vimeo').'?title=0" frameborder="0" allowfullscreen></iframe>\' class="photo_medias" >';?>

答案 1 :(得分:0)

试试这个:

<?php 

$frame = '<iframe width="706" height="364"  src="//player.vimeo.com/video/'.the_sub_field('vimeo'). '" title=0" frameborder="0" allowfullscreen></iframe>';

echo '<img src="' . get_vimeo_thumb(get_sub_field('vimeo'), 'thumbnail_large') . '" data-videofull="'.$frame.'" class="photo_medias" >';

?>
相关问题