将多个JavaScript文件添加到模板标题

时间:2013-02-06 作者:sarah

我有多个要加载的JavaScript文件。在我的header.php和footer.php.

以下是文件:

<?php
<script type="text/javascript src="/scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript src="/scripts/contact.js"></script>
<script type="text/javascript src="/scripts/jquery.easing.1.3.js"></script>
<script src="scripts/jsCarousel-2.0.0.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
    $(\'#carouselv\').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, masked: false, itemstodisplay: 3, orientation: \'v\' });
        $(\'#carouselh\').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, circular: true, masked: false, itemstodisplay: 3, orientation: \'h\' });
        $(\'#carouselhAuto\').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, masked: true, itemstodisplay: 5, orientation: \'h\' });

    });               
</script> ?>

1 个回复
最合适的回答,由SO网友:stealthyninja 整理而成

你不可能<script> PHP中类似的元素。要么将它们从PHP分隔符中去掉(<?php ?>) 或使用wp_register_script()wp_enqueue_script() 在WordPress中获取脚本。

Update

如何将wp\\u enqueue\\u script()与多个脚本一起使用?

wp_register_script( \'jquery-1.8.2\', get_template_directory_uri() . \'/scripts/jquery-1.8.2.min.js\' );
wp_register_script( \'contact\', get_template_directory_uri() . \'/scripts/contact.js\' );
wp_register_script( \'easing-1.3\', get_template_directory_uri() . \'/scripts/jquery.easing.1.3.js\' );
wp_register_script( \'carousel-2.0.0\', get_template_directory_uri() . \'/scripts/jsCarousel-2.0.0.js\' );
wp_register_script( \'starter\', get_template_directory_uri() . \'/scripts/starter.js\' );

wp_enqueue_script( \'jquery-1.8.2\' );
wp_enqueue_script( \'contact\' );
wp_enqueue_script( \'easing-1.3\' );
wp_enqueue_script( \'carousel-2.0.0\' );
wp_enqueue_script( \'starter\' );
然后在starter.js 可以放置的脚本:

$(document).ready(function() {
    $(\'#carouselv\').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, masked: false, itemstodisplay: 3, orientation: \'v\' });
    $(\'#carouselh\').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, circular: true, masked: false, itemstodisplay: 3, orientation: \'h\' });
    $(\'#carouselhAuto\').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, masked: true, itemstodisplay: 5, orientation: \'h\' });
});

结束

相关推荐

Add Adsense code in index.php

我的wordpress博客主页有缩略图库。我想添加adsense图像广告代码到5,10位。下面是我索引中的代码 <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div id=\"post-<?php the_ID(); ?>\" <?php post_class(\'thumb\'); ?>> 我发现以下代码来自here (wordpress.stac