2016-06-29 3 views
0

WordPressテーマにブートストラップスライダーを入れたいと思います。どのように私は特色の画像だけでなく、それに記事を置くことができます。私は本当にプラグインを使いたくない。これを達成するために使用できるWordPress関数はありますか?私はWordPressでかなり新しくなっていますので、どんな助けでも感謝します。WordPressテーマにブートストラップスライダーを使用するにはどうすればいいですか?

答えて

0

クエリーを使用して、カルーセルに記入した結果をループします。これはかなり近いはずです - おそらくあなたの設定で作業するには2つまたはそれ以上の調整が必要です。

$the_query = new WP_Query(array('category_name' => 'staff')); 

// The Loop 
if ($the_query->have_posts()) { 

    ?> 

    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> 
    <!-- Indicators --> 
    <ol class="carousel-indicators">  

     <?php for ($i=1;$i<$the_query->post_count;$i++) { ?> 
      <li data-target="#carousel-example-generic" data-slide-to="<?php echo $i;?>" ></li> 
     <?php } ?> 
    </ol> 

    <div class="carousel-inner" role="listbox"> 

    <?php 
    while ($the_query->have_posts()) { 
     $the_query->the_post(); 
     $title = get_the_title(); 
     $id = get_the_ID(); 

     if (has_post_thumbnail($id)) { 
      $image = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'full'); 
     } 
    ?> 

     <div class="item"> 
      <img src="<?php echo $image; ?>" alt="<?php echo $title;?>"> 
     </div> 

    <?php } ?> 
    </div> 
    </div> 
<?php 
    /* Restore original Post Data */ 
    wp_reset_postdata(); 
} else { 
    // no posts found 
}