【问题标题】:How can I use a bootstrap slider in my WordPress theme如何在我的 WordPress 主题中使用引导滑块
【发布时间】:2016-06-29 13:10:43
【问题描述】:

我想在我的 WordPress 主题中放置一个引导滑块。我怎样才能把特色图片和帖子放在里面。我真的不想使用插件。我可以使用任何 WordPress 功能来实现这一点吗?我是 WordPress 的新手,所以任何帮助都将不胜感激。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    使用查询,在执行过程中循环浏览填写在轮播中的结果。这应该非常接近 - 可能需要进行一两次调整才能与您的设置配合使用。

    $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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-01
      • 1970-01-01
      • 2015-02-02
      相关资源
      最近更新 更多