2012-03-24 33 views

回答

0

我想如果你有WordPress的知識,那麼只需簡單地從你的模板文件夾修改header.php文件。

+0

我該怎麼做? – 2012-03-24 06:24:11

2

如果你不介意使用jQuery插件,而不是從頭開始寫,可能我建議.cycle()

我打算假設你不熟悉WP循環。如果你不是,你真的應該檢查WP Codex(here)。

PHP - (把這個functions.php中)

<?php add_action('wp_enqueue_scripts', 'my_scripts_method'); ?> 
<?php function my_scripts_method() { 
    wp_deregister_script('jquery'); 
    wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'); 
    wp_enqueue_script('jquery'); 
    wp_deregister_script('jqueryui'); 
    wp_register_script('jqueryui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js'); 
    wp_enqueue_script('jqueryui'); 
    wp_register_script('slideshow', get_bloginfo('stylesheet_directory').'js/slideshow.js'); 
    wp_enqueue_script('jqueryui'); 
} ?> 

<?php add_action('hook_name', 'my_slideshow'); ?> 
<?php function my_slideshow() { ?> 
    <?php if(is_page('page_name')) : ?> 
    <div id="SlideShow"> 
    <?php $my_query = new WP_Query('category_name=my-slideshow$post_per_page=5'); ?> 
    <?php if ($my_query->have_posts()) : ?> 
     <?php while ($my_query->have_posts()) : ?> 
     <div id="slide"> 
      <div class="wrapper"> 
         <?php if (has_post_thumbnail()) : ?> 
           <?php the_post_thumbnail() ?> 
         <?php else : ?> 
           <?php echo (get_bloginfo('stylesheet_directory').'/images/default.png'); ?> 
         <?php endif; ?> 
      </div><!-- end .wrapper --> 
     </div><!-- end #slide --> 
     <?php endwhile; ?> 
    <?php else : ?> 
     <span>Sorry, there is no content at this time.</span> 
    <?php endif; ?> 
    <?php wp_reset_postdata(); ?> 
    </div><!-- end #slideshow --> 
    <?php endif; ?> 
<?php } ?> 

取代 'hook_name' 與您要在幻燈片中插入掛鉤。 用想要幻燈片顯示的頁面的slu replace替換'page_name'。如果您希望它顯示在所有頁面上,請在末尾刪除<?php if(is_page('page_name')) : ?><?php endif; ?>。 將$my_query中的'my-slideshow'替換爲幻燈片中所需的類別名稱。 您可以將'5'更改爲幻燈片中要顯示的任意數量的幻燈片。 the_post_thumbnail是該帖子的精選圖片。它正在檢查帖子是否有精選圖片,如果沒有,則依賴主題圖片文件夾中的default.png。

的jQuery - (把這個在它自己的文件的主題目錄的/ JS目錄調用文件slideshow.js。)

var $j = jQuery.noConflict(); 

$j(document).ready(function() { 
    $j('#slideshow').cycle({ 
     // options here. 
    }); 
}); 

有,你可以定義發現here很多選擇。

這幾乎總結了自定義幻燈片。如果您想將其打包爲模塊化插件,則需要參考Codex here