Embed Vimeo/youtube Video as Loop in Sidebar with Values of a Custom Field Array
-
Hello there,
Let’s see if i can explain myself in english and hope that I am in the right forum for this question.
In my post i have three Custom Fields (wpcf-video_embed_trailer, wpcf-video_embed_extras, wpcf-video_embed_example). Each field can contain more than one link. I want to show the links from the arrays embedded in my sidebar. My Company wants to be able to put youtube and vimeo links there.
I already found a piece of code and altered it, so that the ID from the first key gets extracted and inserted into a shortcode in the sidebar which then embeds the video as i please ;). This works just fine for a one key. But i want every key with their values displayed in the sidebar.
I know that i need a loop with foreach. But i don’t know how to approach this, for not one custom field array but for three. Not quite enough PHP knowledge (wordpress hooks are all i know) for this.
Can anyone give me guidance or a hint how to achieve this?
I can’t give you the link for my page because of company security.<?php // Check if youtube or Vimeo and Extract the IDS. Displayed with Shortcode in Sidebar global $wp_query; $postid = $wp_query->post->ID; $wpcf_video = get_post_meta($postid, 'wpcf-video_embed_trailer', true); $parsed = parse_url($wpcf_video); $hostname = $parsed['host']; $query = $parsed['query']; $path = $parsed['path']; //print_r($parsed); $Arr = explode('v=',$query); // from video id, until to end of the string $videoIDwithString = $Arr[1]; $videoID = substr($videoIDwithString,0,11); //print_r($videoID); $yt1 = '[youtube id="'; $yt2 = '" mode="thumbnail"]'; //YOUTUBE.COM if( (isset($videoID)) && (isset($hostname)) && ($hostname=='www.youtube.com' || $hostname=='youtube.com')){ ?> <?php echo do_shortcode($yt1.=$videoID.=$yt2); ?> <?php } ?> <?php $v1 = '[vimeo id="'; $v2 = '" mode="thumbnail"]'; //VIMEO.COM //https://vimeo.com/45980982 if((isset($hostname)) && $hostname=='vimeo.com'){ $ArrV = explode('://vimeo.com/',$path); // from ID to end of the string $videoID = substr($ArrV[0],1,8); // to get video ID $vimdeoIDInt = intval($videoID); // ID must be integer //print_r($vimdeoIDInt); ?> <?php echo do_shortcode($v1.=$vimdeoIDInt.=$v2); ?> <?php } ?>
- The topic ‘Embed Vimeo/youtube Video as Loop in Sidebar with Values of a Custom Field Array’ is closed to new replies.