2012-02-22 60 views

回答

0

1 - 你应该打电话给你的jQuery脚本到的header.php

2 - 然后指定如果是的pageid到相同的PHP文件。如果页面ID正确,请调用您的函数。

3 - 在页面的内容输入正确的html代码

注意:确保你打电话给jQuery函数之前,你的HTML代码加载。

EtVoilà!

+0

谢谢DAV刚刚接近这个 <?php wp_ enqueue_script( '的jquery'); ?> <?php wp_head(); ?> <脚本类型= “文/ JavaScript的” SRC = “/JS/accordion.js”> 但请不要让我知道如何指定的pageid并调用我的功能,如果页面ID是正确的? – 2012-02-22 19:52:57

0

克利须那,

得很不喜欢这个

<?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(); ?>