Jump to content

PHP Simple question


jemsz

Recommended Posts

Gretings all.

Right now i use wordpress and in my post i can add a Video by entering the Youtube address into a Custom field called "video_url" and then it outputs the video on my site wich works easy, here it is:

<div class="video">

      <html><center>  
<?php
$meta_value = get_post_meta($post->ID, 'video_url', true);
if($meta_value){
$url = parse_url($meta_value);
$id = 0;
if($url['host'] == 'youtu.be'){$id = ltrim($url['path'],'/');}
else if(strpos($url['path'],'embed') == 1){$id = end(explode('/',$url['path']));}
else{parse_str($url['query']);$id = $v;}
echo '<p><iframe width="540" height="355" frameborder="1" allowfullscreen="true"  src="http://www.youtube.com/embed/'.$id.
'?version=3&theme=light&fs=1&rel=0&cc_load_policy=1&iv_load_policy=1&modestbranding=1" type="application/x-shockwave-flash" allowScriptAccess="always" allowfullscreen="true" width="600" height="355">
</iframe></p>';
}


?>

</div>

However i am tring to add this Modification here in wich adding the video link custom field will also bring back the youtube video title and descripiton,

<?php
$video_id = ’48J_DIZBNyE’;
$video_info = simplexml_load_file(‘http://gdata.youtube.com/feeds/api/videos/’.$video_id.’?v=1′);
echo $video_info->title . ‘<hr>’; // title
echo $video_info->content; // description
?>

Could anyone please help me implement the bottom code with the top piece of code !!

Mucg respect><

Thanks

Link to comment
Share on other sites

Does this help you?

 

<div class="video">
 
      <html><center>  
<?php
$meta_value = get_post_meta($post->ID, 'video_url', true);
if($meta_value){
   $url = parse_url($meta_value);
   $id = 0;
   if($url['host'] == 'youtu.be'){
      $id = ltrim($url['path'],'/');
   } else if(strpos($url['path'],'embed') == 1){
      $id = end(explode('/',$url['path']));
   }
} else {
   parse_str($url['query']);
   $id = $v;
}
$video_info = simplexml_load_file(‘http://gdata.youtube.com/feeds/api/videos/’.$id.’?v=1');
 
echo '<h3>'.$video_info->content.'</h3><hr /><p><iframe width="540" height="355" frameborder="1" allowfullscreen="true"  src="http://www.youtube.com/embed/'.$id.
'?version=3&theme=light&fs=1&rel=0&cc_load_policy=1&iv_load_policy=1&modestbranding=1" type="application/x-shockwave-flash" allowScriptAccess="always" allowfullscreen="true" width="600" height="355">
</iframe></p><p>'.$video_info->content;.'</p>';
 
?>
 
</div>
NB: *Not* linted.... Edited by dalecosp
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.