How to use the jQuery Cycle Plugin with WordPress?


Question

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

1
1
5/29/2009 1:33:22 PM

Accepted Answer

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')); ?>
2
4/13/2017 5:37:41 PM

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


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon