2009-05-29 54 views
1

我嘗試了所有我能想到的。它不應該這麼難。有人可以向我解釋使用jQuery與WordPress(特別是jQuery Cycle Plugin)的過程嗎?如何在WordPress中使用jQuery Cycle插件?

在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文件到我的主題目錄。

在功能,工作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 2011-09-27 19:30:33

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

否則,它只是罰款