WordPress YouTube播放列表随机功能

时间:2014-08-14 23:46:47

标签: wordpress iframe random embed playlist

我正在尝试在编辑器中为WordPress的iframe连接一个随机变量并且无法正常工作,总是向我显示我的播放列表的第一个视频,实际上我想每次有人为我的播放列表更新不同的视频在我们的网站上 我的javascript看起来像这样

'<iframe src="//www.youtube.com/embed/?list=PL428169F9EB17A5F8&amp;index=' + rand(0,3) + '" width="320" height="180" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'

任何帮助?

1 个答案:

答案 0 :(得分:0)

WordPress将功能限制为post iframes。它只是管理员。它可以关闭,但最好的解决方案是create Shortcodes,因此用户只需将[something]添加到内容中,iframe就会毫无问题地打印出来。

add_shortcode( 'rand_yt', 'rand_so_25319303' );

function rand_so_25319303( $atts, $content = null ) 
{
    $output = sprintf(
        '<iframe src="//www.youtube.com/embed/?list=PL428169F9EB17A5F8&amp;index=%s" width="320" height="180" frameborder="0" allowfullscreen="allowfullscreen"></iframe>', 
        rand(0,3) 
    );
    return $output;
}

另一个选择是将<?php echo do_shortcode('rand_yt'); ?>添加到主题模板。