2009-05-29 15 views
1

私は考えることができるすべてを試しました。これは難しいことではありません。 WordPress(特にjQuery Cycle Plugin)でjQueryを使用するプロセスを私に説明してください。私はheader.phpの中WordPressでjQuery Cycle Pluginを使用するには?

<?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ファイルをアップロードしました。私が持っている機能を備えた作業-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

あなたの人生を容易にするためにget_bloginfo( "stylesheet_directory")を投げる動作します
<?php wp_enqueue_script('jquery.cycle.all', get_bloginfo("stylesheet_directory") . '/js/jquery.cycle.all.js', array('jquery')); ?> 
+0

ニース!その機能が存在するかどうかは分かりませんでした。しかし、なぜ彼らがjavascriptファイルであるときに "スタイルシートディレクトリ"を指定していますか? 「javascriptsディレクトリ」機能はありますか? – Andrew

+0

@Andrew指定された 'js'ディレクトリはありませんが、[get_template_directory_uri()](http://codex.wordpress.org/Function_Reference/get_template_directory_uri)または[get_stylesheet_directory_uri](http://codex.wordpress .org/Function_Reference/get_stylesheet_directory_uri)。 –

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

されている必要がありますそれだけで罰金

関連する問題