我一直在爲我的自定義(而不是一個插件)的WordPress的jQuery幻燈片。我一整天都在搜索如何在Wordpress中集成JavaScript,但似乎遇到了很多不同的方法。所以我的主要問題是哪種方式是編寫腳本的正確,最快的方式。使用JQuery和Wordpress的正確方法?
從我看到它看起來像我應該使用Wordpress入隊,以便該腳本只在需要的頁面上調用,在我的情況下是index.php。但我不確定正確的做法。另外,我應該添加一些東西到我的functions.php?
下面是腳本:
<script src="Js/js/jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="Js/js/jquery.zaccordion.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#example4 ul").zAccordion({
slideWidth: 600,
width: 900,
height: 250,
timeout: 5000,
slideClass: "frame"
});
});
</script>
而這正是我現在在我的header.php:
<?php wp_enqueue_script('jquery'); ?>
<?php wp_head();?>
<script type="text/javascript"
src="<?php bloginfo("template_url"); ?>/js/jquery-1.6.1.min.js"></script>
<script type="text/javascript"
src="<?php bloginfo("template_url"); ?>/js/jquery.zaccordion.js"></script>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery("#slider ul").zAccordion({
slideWidth: 600,
width: 800,
height: 250,
timeout: 5000,
slideClass: "frame"
});
});
</script>