doubiao9775 2014-03-08 14:51
浏览 44
已采纳

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

I'm using my data to get an iframe src, because I'm using this data in my function.js.

for example, with this youtube video :

my custom field with the youtube id :

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

my thumbnail is :

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

and my Iframe :

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

and when adding this to a img data :

<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">

it works perfectly.

Now I'm trying to generate another data-videofull but with a vimeo code, which is a bit different to generate the thumbnail and to display it

here is my custom field with vimeo id :

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

my thumbnail is (this is where it's a bit different, I need to use echo inside)

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

my iframe (same as for youtube)

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

but when trying to add the iframe adress into data-videofull, I have a php error...

this is what I tried, but it's not working :

<?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" >';?>

I guess the problem comes from the echo of my img src but I have to use it...

can anybody help me with this ?

thanks a lot for your help,

  • 写回答

2条回答 默认 最新

  • dtny30176 2014-03-08 14:56
    关注

    There is something wrong, you need to escape single quotes and also don't put php tags inside php other tags but concatenate your strings and functions. Also you have a double double quotes which i removed.

    <?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条)

报告相同问题?

悬赏问题

  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改