破碎的功能.php;如何将脚本从bootstrap移动到WordPress?

时间:2013-11-15 18:12:14

标签: javascript wordpress twitter-bootstrap

我是bootstrap和WordPress的新手,并尝试整理一个简单的页面。因此,我遇到依赖性问题,从页眉和页脚添加和注册脚本都不会让我感到惊讶。

这里有什么明显的东西让我失踪吗?

<?php 

function wpbootstrap_scripts_with_jquery()
{

// register the script like this for a theme:
    wp_register_script( 'custom-script', get_template_directory_uri() . 'js/bootstrap.js', array( 'jquery' ) );     
    wp_register_script( 'jquery-tweet', get_template_directory_uri() . 'js/jquery.tweet.js', array( 'jquery' ) );
    wp_register_script( 'clock', get_template_directory_uri() . 'js/clock.js', array( 'jquery' ) ); 
    wp_register_script( 'soon', get_template_directory_uri() . 'js/soon.js', array( 'jquery' ) );

//footer scripts     
    wp_register_script( 'dat-gui-min-js', get_template_directory_uri() . 'js/dat.gui.min.js' );
    wp_register_script( 'fss', get_template_directory_uri() . 'js/fss.js');
    wp_register_script( 'bgCustom', get_template_directory_uri() . 'js/bgCustom.js');


// For either a plugin or a theme, you can then enqueue the script:
    wp_enqueue_script( 'custom-script','jquery-tweet','clock','soon','dat-gui-min-js','fss','bgCustom');
}

add_action( 'wp_enqueue_scripts', 'wpbootstrap_scripts_with_jquery' );

?>

在header.php中

<?php wp_enqueue_script("jquery"); ?>
<?php wp_head(); ?>

1 个答案:

答案 0 :(得分:2)

我相信您为wp_register_script注册的每个脚本都需要一个唯一的名称。例如,您将所有这些命名为“custom_script”。我会将每个名称命名为其JavaScript文件(仅为方便起见)。例如......

wp_register_script( 'jquery-tweet', get_template_directory_uri() . 'js/jquery.tweet.js', array( 'jquery' ) );
wp_register_script( 'clock', get_template_directory_uri() . 'js/clock.js', array( 'jquery' ) );

...等等然后你会把每个人排队......

wp_enqueue_script( 'jquery-tweet' );
wp_enqueue_script( 'clock' );

......等等。

希望有所帮助,玩得开心!