1

私は考えられるすべてを試しました。そんなに難しいことではないはずです。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();
?>

これらの2つのjsファイルをテーマのディレクトリにアップロードしました。

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

私は何が間違っているのですか?

4

2 に答える 2

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

それ以外の場合は、問題なく動作します

于 2009-05-29T14:02:12.477 に答える
2

get_bloginfo("stylesheet_directory") をスローして、生活を楽にします

 <?php wp_enqueue_script('jquery.cycle.all', get_bloginfo("stylesheet_directory") . '/js/jquery.cycle.all.js', array('jquery')); ?>
于 2011-09-27T18:54:12.810 に答える