AshleyQuick Posted September 15, 2013 Share Posted September 15, 2013 Can someone assist with a code snippet that will randomly display YouTube videos using their embed code? <iframe width="560" height="315" src="//www.youtube.com/embed/bYI_aOyCn9Y" frameborder="0" allowfullscreen></iframe> I'd like to cycle through 3-4 videos. Link to comment https://forums.phpfreaks.com/topic/282172-displaying-random-youtube-videos/ Share on other sites More sharing options...
Guber-X Posted September 15, 2013 Share Posted September 15, 2013 are you looking for it to random on page load or randomize after time period? ps. my assumption is that you are looking for a php snippet to do this? Link to comment https://forums.phpfreaks.com/topic/282172-displaying-random-youtube-videos/#findComment-1449602 Share on other sites More sharing options...
AshleyQuick Posted September 15, 2013 Author Share Posted September 15, 2013 Random on page load. And yep, a php snippet. I found something similar here: <?php $content = array( 'http://www.address1.com|image1|Caption 1', 'http://www.address2.com|image2|Caption 2', 'http://www.address3.com|image3|Caption 3', 'http://www.address4.com|image4|Caption 4' ); shuffle($content); foreach ($content as $value) { $explode = explode('|', $value); echo '<p><a href="' . $explode[0] . '"><img src="/misc/php/shuffle/' . $explode[1] . '.gif" border="0" width="100" height="25" align="absmiddle"></a> <a href="' . $explode[0] . '">' . $explode[2] . '</a></p>'; } ?> But I couldn't get that to work with the YouTube code. Link to comment https://forums.phpfreaks.com/topic/282172-displaying-random-youtube-videos/#findComment-1449605 Share on other sites More sharing options...
priyankagound Posted September 16, 2013 Share Posted September 16, 2013 Try out with this one... <?php $file = "path/to/text/file.txt"; $data = file($file); $line = trim($data[rand(0,count($data))]); echo '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/watch?v='.$line.'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/watch?v='.$line.'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>'; ?> Link to comment https://forums.phpfreaks.com/topic/282172-displaying-random-youtube-videos/#findComment-1449673 Share on other sites More sharing options...
AshleyQuick Posted September 17, 2013 Author Share Posted September 17, 2013 That could work but is it possible to have everything contained in the script (without the external text file)? I'm using this in Wordpress so I'd like to edit in one place only. Link to comment https://forums.phpfreaks.com/topic/282172-displaying-random-youtube-videos/#findComment-1449819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.