Question

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,

Était-ce utile?

La solution

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

Autres conseils

Try this:

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

?>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top