• Resolved leoly

    (@leoly)


    Hello,
    We have the following shortcode for a Playlist –
    [lyte id="PLID" audio=”true” playlist=”true” /]

    We would like for the playlist to start from a random number – which was achieved by doing the following and adding to a PHP page template –
    <iframe src="https://www.youtube.com/embed?listType=playlist&list=PLID&index=<?php print(rand(1,200)) ?>" width="560" height="315" frameborder="0"></iframe>

    We can get the shortcode to work from the template via –
    <?php echo do_shortcode('[lyte id="PLID" audio=”true” playlist=”true” /]'); ?>

    Is there a way to add the &index into the shortcode, so that the playlist can start from a random number? The iframe does what we need, but we like the audio-only feature of the plugin. So if there is a way to style the iframe to look like the audio-only styling, that would help as well. Thanks.

Viewing 15 replies - 1 through 15 (of 18 total)
  • Plugin Author Frank Goossens

    (@futtta)

    you can try <?php echo do_shortcode('[lyte id="PLID&index='.print(rand(1,200)).'" audio=”true” playlist=”true” /]'); ?>, i’ve seen others having some success with this non-official approach (although I think it was for individual video’s, not playlists). no guarantees though 🙂

    frank

    Thread Starter leoly

    (@leoly)

    Thank you for the prompt response. Unfortunately, it keeps printing out this error –

    148" audio=”true” playlist=”true” /][lyte id="PLID&index=1

    Where the 148 above is a number that changes with each refresh, so it is printing out a random number, but putting it in the wrong place, and thus breaking the code.

    Is it possible to make the changes in a similar method has mentioned in these topics – https://wordpress.org/support/topic/individual-playlist-not-working/
    https://wordpress.org/support/topic/problems-with-playlists-in-custom-fields/

    Or is there a way to add a filter to YouTube iframes for mobile, in a similar method has mentioned here –

    add_filter('lyte_do_mobile','lyte_on_mobile',10,0);
    function lyte_on_mobile(){
        return true;
    }

    Really appreciate the assistance, thanks

    Plugin Author Frank Goossens

    (@futtta)

    and <?php echo do_shortcode('[lyte id="PLID&index='.rand(1,200).'" audio=”true” playlist=”true” /]'); ?> ?

    Thread Starter leoly

    (@leoly)

    The shortcode isn’t broken, but the print out on the page – strips out the index info, so the html looks like the below (?index doesn’t show, just goes back to &autoplay, like with the regular shortcode).

    <iframe id="iF_PLID" src="https://www.youtube.com/embed/videoseries?list=PLID&autoplay=1&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd=0&autohide=0" style="position:relative;top:-400px;" allowfullscreen="" frameborder="0" height="438" width="840"></iframe>

    Is there a way to add it to the js file that adds the other YouTube parameters, i.e. controls, wmode, etc. Basically, a way to generate a random number, within the js script.

    Thanks again for the assistance.

    Plugin Author Frank Goossens

    (@futtta)

    that looks like the HTML after clicking play, what’s the HTML before having clicked play?

    Thread Starter leoly

    (@leoly)

    This is the html before clicking play with &index=’.rand(1,200).’

    <div class="lyte lyte-audio playlist lP" id="WYL_PLID"><div id="lyte_PLID" data-src="" class="pL"><div class="tC"><div class="tT">Playlist:Mix</div></div><div class="play"></div><div class="ctrl"><div class="Lctrl"></div><div class="Rctrl"></div></div></div><noscript><a href="http://youtube.com/playlist?list=PLID"><br />Watch this playlist on YouTube</a></noscript></div>

    Plugin Author Frank Goossens

    (@futtta)

    ok, think I’ve got it;

    
    add_filter('lyte_match_postparse_template','playlist_randomizer');
    function playlist_randomizer($in) {
      return str_replace('class="lyMe playlist"','class="lyMe playlist qsa_\&index\='.rand(1,200).'"',$in);
    }
    

    enjoy 🙂

    Thread Starter leoly

    (@leoly)

    Huge thanks for trying to help figure this out. Added the above code to functions.php and then tried out the shortcode in two ways:

    added to a page template – <?php echo do_shortcode('[lyte id="PLID" audio=”true” playlist=”true” /]'); ?>

    added to a page – [lyte id="PLID" audio=”true” playlist=”true” /]

    and in both cases the index information was stripped out of the final html, just like before.

    Plugin Author Frank Goossens

    (@futtta)

    hmm, can you try with a normal youtube playlist link in a post instead? that’s how I tested.

    Thread Starter leoly

    (@leoly)

    Apologies, you were right, it does work. We were getting an error, because of the audio only part. So: [lyte id=”PLID” audio=”true” playlist=”true” /] doesn’t work, the index info is stripped out, but [lyte id=”PLID” playlist=”true” /] works.

    Hurray 😀 Would appreciate if you can help with the styling to just show the audio only. Thanks and left a review as well.

    • This reply was modified 9 years ago by leoly.
    Plugin Author Frank Goossens

    (@futtta)

    indeed, we need to add the lyte-audio to the list of classes to make it work;

    add_filter('lyte_match_postparse_template','playlist_randomizer');
    function playlist_randomizer($in) {
      return str_replace('class="lyMe lyte-audio playlist"','class="lyMe lyte-audio playlist qsa_\&index\='.rand(1,200).'"',$in);
    }

    thanks for the kind review 🙂

    frank

    Thread Starter leoly

    (@leoly)

    Works well, thanks again 🙂

    Just for the future, is there a way to create an array so that the randomizer works for both the lyMe playlist and lyMe lyte-audio playlist at the same time.

    • This reply was modified 9 years ago by leoly.
    Plugin Author Frank Goossens

    (@futtta)

    an array would not work, as the replace-argument of str_replace would not have the correct classes any more. so either go regex (but let’s not) or try e.g.

    add_filter('lyte_match_postparse_template','playlist_randomizer');
    function playlist_randomizer($in) {
      return str_replace('class="lyMe ','class="lyMe qsa_\&index\='.rand(1,200),$in);
    }
    Thread Starter leoly

    (@leoly)

    Unfortunately, that didn’t work. But we have taken too much of your time already. Thanks again for the continued follow up 👍. Below where the html print outs for the audio only shortcode and the full video.

    <div class="lyte qsa_\&index\=166lyte-audio playlist lP" id="PLID">
    <iframe id="iF_PLID" src="https://www.youtube.com/embed/videoseries?list=PLID&autoplay=1&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd=0&index=166lyte-audio playlist&autohide=0" style="position:relative;top:-400px;" allowfullscreen="" frameborder="0" height="438" width="1060"></iframe></div>
    <div class="lyte qsa_\&index\=163playlist lP" id="PLID">
    <iframe id="iF_PLID" src="https://www.youtube.com/embed/videoseries?list=PLID&autoplay=1&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd=0&index=163playlist" style="" allowfullscreen="" frameborder="0" height="298" width="1060"></iframe></div>
    Thread Starter leoly

    (@leoly)

    Also tried this

    add_filter('lyte_match_postparse_template','playlist_randomizer');
    function playlist_randomizer($in) {
      return str_replace('class="lyMe ','class="lyMe qsa_\&index\='.rand(1,200).'"',$in);
    }

    and got this, which killed the playlist, because it printed out as embed/PLID, instead of embed/videoseries?list=PLID

    <div class="lyte qsa_\&index\=41 lP" lyte-audio="" playlist"="" id="PLID"><iframe id="PLID" src="https://www.youtube.com/embed/PLID?autoplay=1&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd=0&index=41" style="" allowfullscreen="" frameborder="0" height="38" width="1060"></iframe></div>
    
    <div class="lyte qsa_\&index\=186 lP" playlist"="" id="PLID"><iframe id="PLID" src="https://www.youtube.com/embed/PLID?autoplay=1&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd=0&index=186" style="" allowfullscreen="" frameborder="0" height="298" width="1060"></iframe></div>
Viewing 15 replies - 1 through 15 (of 18 total)

The topic ‘Shortcode For Playlist’ is closed to new replies.