如何在WordPress主题中使用引导滑块

时间:2016-06-29 13:10:44

标签: wordpress

我想在我的WordPress主题中添加一个引导滑块。我怎么能把精选图像,以及其中的帖子。我真的不想使用插件。我可以使用任何WordPress功能来实现这一目标吗?我是WordPress的新手,所以任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

使用查询,循环填充旋转木马中的结果。这应该非常接近 - 可能需要一两个调整才能使用您的设置。

$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
}
相关问题