克利須那,
得很不喜歡這個
<?php wp_enqueue_script('jquery-1.3.2.min', 'wp-content/themes/xyz/js/jquery-1.3.2.min.js'); ?>
<?php wp_enqueue_script('custom', 'wp-content/themes/xyz/js/accordion.js'); ?>
<?php get_header(); ?>
<?php get_sidebar(); ?>
或如你可以像這樣
if(is_page('x')) { ?>
// YOUR SCRIPT STUFF
<?php }
另外,請檢查你的主題function.php文件,如果這些存在,那麼你所做的
function scripts() {
if (!is_admin()) { // this if statement will insure the following code only gets added to your wp site and not the admin page cause your code has no business in the admin page right unless that's your intentions
// jquery
wp_deregister_script('jquery'); // this deregisters the current jquery included in wordpress
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"), false); // this registers the replacement jquery
wp_enqueue_script('jquery'); // you can either let wp insert this for you or just delete this and add it directly to your template
// your own script
wp_register_script('yourscript', (get_bloginfo('template_url') . '/yourscript.js'), false); //first register your custom script
wp_enqueue_script('swfobject'); // then let wp insert it for you or just delete this and add it directly to your template
// just in case your also interested
wp_register_script('yourJqueryScript', (get_bloginfo('template_url') . '/yourJquery.js'), array('jquery')); // this last part-(array('jquery'))is added in case your script needs to be included after jquery
wp_enqueue_script('yourJqueryScript'); // then print. it will be added after jquery is added
}
}
add_action('wp_print_scripts', 'scripts'); // now just run the function
所以最後你可以做這樣的
<?php
function load_index_page(){
wp_enqueue_script('jquery-1.3.2.min', 'wp-content/themes/xyz/js/jquery-1.3.2.min.js');
wp_enqueue_script('easySlider1.5', 'wp-content/themes/xyz/js/accordion.js');
}?>
<?php if (is_home()){
add_action('init', load_index_page);
} ?>
<?php wp_head(); ?>
謝謝DAV剛剛接近這個 <?php wp_ enqueue_script( '的jquery'); ?> <?php wp_head(); ?> <腳本類型= 「文/ JavaScript的」 SRC = 「/JS/accordion.js」> 但請不要讓我知道如何指定的pageid並調用我的功能,如果頁面ID是正確的? –
2012-02-22 19:52:57