2013-05-02 92 views
1

我想每10秒加载一次php脚本。负载代码是没有问题的,但在WordPress的所有插件使用自己的jQuery的库,如果我只是添加了jQuery谷歌链接:如何在我的Wordpress页脚中包含Jquery?

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script> 

其他插件会崩溃。

我在页脚下面的代码:

<?php 
if (is_user_logged_in()) { 
include 'completed.php'; 
} 
?> 

我想包括jQuery脚本,所以我可以执行以下代码:

<?php 
if (is_user_logged_in()) { ?> 
<div id="completed"> 
    <script> 
    $(function(){ 
     setInterval(function(){ 
       $("#completed").load("completed.php"); 
     }, 10 * 1000); 
    }); 
    </script> 
</div> 
<?php } ?> 

你认为你能帮助我?

+0

在http://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page – MrGlass 2013-05-02 17:28:54

回答

4

负载从谷歌AJAX库中尾

function my_init() { 
    if (!is_admin()) { 
     // comment out the next two lines to load the local copy of jQuery 
     wp_deregister_script('jquery'); 
     wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', false, '1.3.2', true); 
     wp_enqueue_script('jquery'); 
    } 
} 
add_action('init', 'my_init'); 
+0

看看好了,我会尝试。但我可以问为什么IF语句不包含管理员? – swordsecurity 2013-05-02 17:30:47

+0

!is_admin()是为了防止仪表板页面中的任何影响 – 2013-05-02 17:35:17

+0

谢谢你的帮助泰米尔Selvan。 – swordsecurity 2013-05-02 18:36:06

0

jQuery的,但你为什么不就在无冲突模式,使得没有崩溃使用内置的jQuery的。

<?php 
if (is_user_logged_in()) { ?> 
<div id="completed"> 
<script> 
    jQuery(function(){ 
    setInterval(function(){ 
      jQuery("#completed").load("completed.php"); 
    }, 10 * 1000); 
    }); 
</script> 
</div> 
<?php } ?> 
相关问题