最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to use the jQuery Cycle Plugin with WordPress? - Stack Overflow

programmeradmin7浏览0评论

I have tried everything that I can think of. It shouldn't be this hard. Can some one please explain to me the process of using jQuery with WordPress (specifically jQuery Cycle Plugin)?

in header.php I have:

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

I have uploaded those two js files to my theme's directory.

In featured-work-slideshow.js I have:

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

And in my template, I have:

<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>

What am I doing wrong???

I have tried everything that I can think of. It shouldn't be this hard. Can some one please explain to me the process of using jQuery with WordPress (specifically jQuery Cycle Plugin)?

in header.php I have:

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

I have uploaded those two js files to my theme's directory.

In featured-work-slideshow.js I have:

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

And in my template, I have:

<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>

What am I doing wrong???

Share Improve this question asked May 29, 2009 at 13:33 AndrewAndrew 239k195 gold badges531 silver badges718 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

I've figured it out. I accidentally forgot to specify the right path:

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

should have been

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

otherwise, it works just fine

throw a get_bloginfo("stylesheet_directory") to make your life easier

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

评论列表(0)

  1. 暂无评论