Jplayer和wordpress 3.6.x

时间:2013-10-15 02:26:42

标签: wordpress jplayer

我正在将我的Jplayer代码嵌入到我的网站中,但是在wordpress安装中已经存在jquery但是当我在播放器中复制我的代码时,因为它没有显示带有x的音量图标。当我包含一个外部jquery脚本时,它会破坏entrie站点,但播放器可以工作。我有没有更好的方法将jPlayer包含在我的wordpress网站中?

1 个答案:

答案 0 :(得分:1)

排队的jPlayer脚本必须通过WordPress规则播放。最简单(也许是唯一的)方式是使用Shortcode。有很多开发人员,主要是主题开发人员,忽略we don't dequeue the bundled jQuery version并从某些CDN加载任何版本(至少,我们不知道我们正在做什么)。

这是一个粗略的测试,短代码回调函数必须经过多次抛光。

public function plugin_setup() // hooked into plugins_loaded 
{
    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue' ) );
    add_shortcode( 'jplayer', array( $this, 'shortcode' ) );
}

public function enqueue()
{
    wp_register_script(
        'sj-jplayer', 
        $this->plugin_url . 'js/jquery.jplayer.min.js', 
        array( 'jquery' ), // <------- Dependencies
        false,
        true
    );
    wp_register_style( 'sj-skin', $this->plugin_url . 'skin/blue.monday/jplayer.blue.monday.css' );

    wp_enqueue_script( 'sj-jplayer' );
    wp_enqueue_style( 'sj-skin' );
}

public function shortcode( $atts, $content )
{
    ob_start();
    require_once('html-shortcode.php');
    $var = ob_get_clean();
    return $var;
}

文件html-shortcode基本上是this demo代码,如:

<?php
/*
 * Prints the shortcode
 */
?>
<script type="text/javascript">
    jQuery(document).ready(function($) // <------ WP noConflict 
    {
        $("#jquery_jplayer_1").jPlayer({});
    });
</script>

<div id="jquery_jplayer_1" class="jp-jplayer"></div>

我在另一个jScrollPane内测试了这个jPlayer短代码,它可以在iPad上运行。