2013-10-15 69 views
0

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

+0

我不能遗憾的代码仍然被网站所有者隐藏。但它的基本代码和播放器一次不在wordpress中,包括外部jquery文件。 –

+0

查看JavaScript错误控制台当您使用现有的jQuery时究竟发生了什么事情 –

回答

1

jPlayer script enqueueing 必须按照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> 

我测试了这个jPlayer简码内的另一个,做了jScrollPane,和它的工作在iPad上。

+0

我实际上所做的是将播放器放入iframe中。它不干净,但它的工作 –