如何将这个JQuery Accordion添加到Wordpress

时间:2012-02-22 19:09:39

标签: jquery wordpress

下面是一个jQuery手风琴

http://dl.dropbox.com/u/24708866/labs/jquery-multi-open-accordion/index.html

我想将其添加到Wordpress网站页面。

并且只想加载到特定页面,因此 jquery-ui-1.8.13.custom.min.js jQuery .multi-accordion-1.5.3.js 不会加载到其他帖子或页面。

我不想使用任何插件这可能吗?

2 个答案:

答案 0 :(得分:1)

Hare Krishna,

喜欢这个

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

答案 1 :(得分:0)

1 - 您应该将jQuery脚本调用到header.php

2 - 然后将pageid指定为同一个php文件。如果页面ID正确,请调用您的函数。

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

注意:在调用jquery函数之前,请确保已加载html代码。

EtVoilà!