0

我正在使用我的数据来获取 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">

它完美地工作。

现在我正在尝试生成另一个 data-videofull 但使用 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 的回声,但我必须使用它......

有人可以帮我吗?

非常感谢你的帮助,

4

2 回答 2

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" >';?>
于 2014-03-08T14:56:29.200 回答
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" >';

?>
于 2014-03-08T14:59:57.873 回答