如何在WordPress中使用jQuery Cycle Plugin?

时间:2009-05-29 13:33:23

标签: php javascript jquery wordpress jquery-plugins

我尝试过所有我能想到的东西。不应该这么难。有人可以向我解释一下在WordPress中使用jQuery的过程(特别是jQuery Cycle Plugin)吗?

在header.php中的

我有:

<?php
    wp_enqueue_script('jquery.cycle.all.min', '/wp-content/themes/andrewhavens/jquery.cycle.all.min.js', array('jquery'));
    wp_enqueue_script('featured-work-slideshow', '/wp-content/themes/andrewhavens/featured-work-slideshow.js');
    wp_head();
?>

我已将这两个js文件上传到我的主题目录。

在feature-work-slideshow.js中我有:

jQuery(document).ready(function($) {
    $('#featured-works').cycle('fade');
});

在我的模板中,我有:

<div id="featured-works">
    <?php query_posts('category_name=featured-work&showposts=5'); ?>
    <?php while (have_posts()) : the_post(); ?>
        <div class="featured-work">
            <div class="featured-work-image-container" style="float:left; width:600px;">
                <?php $image = get_post_meta($post->ID, 'homepage-image', true); ?>
                <img src="<?php echo $image; ?>" width="500" height="300" style="margin-left:30px;">
            </div>
            <p style="float:left; width:300px;">
                <?php the_title(); ?><br />
                <a href="<?php the_permalink() ?>">Read More!</a>
            </p>
        </div>
    <?php endwhile;?>
</div>

我做错了什么???

2 个答案:

答案 0 :(得分:4)

我已经弄清楚了。我不小心忘了指定正确的路径:

<?php
    wp_enqueue_script('jquery.cycle.all.min', '/wp-content/themes/andrewhavens/jquery.cycle.all.min.js', array('jquery'));
    wp_enqueue_script('featured-work-slideshow', '/wp-content/themes/andrewhavens/featured-work-slideshow.js');
    wp_head();
?>

应该是

<?php
   wp_enqueue_script('jquery.cycle.all.min', '/wp-content/themes/andrewhavens/js/jquery.cycle.all.min.js', array('jquery'));
   wp_enqueue_script('featured-work-slideshow', '/wp-content/themes/andrewhavens/js/featured-work-slideshow.js');
   wp_head();
?>

否则,它工作得很好

答案 1 :(得分:2)

抛出get_bloginfo(“stylesheet_directory”),让您的生活更轻松

 <?php wp_enqueue_script('jquery.cycle.all', get_bloginfo("stylesheet_directory") . '/js/jquery.cycle.all.js', array('jquery')); ?>