php - Bootstrap 轮播指示器未在 Wordpress 中显示

标签 php wordpress twitter-bootstrap

我正在尝试将 Bootstrap 轮播作为推荐 slider 集成到我的 Wordpress 主题中。推荐和 Logo 会显示(我正在使用自定义帖子类型),但唯一不显示的是轮播指示器。我浏览了许多 Stackoverflow 问题和其他网页,但找不到解决方案。

有人可以看一下我的代码并看看我是否可以采取任何措施来修复它吗?感谢您的帮助。

<ol class="carousel-indicators">
            <?php
                $args = array(
                    'post_type' => 'testimonial',
                    'orderby'   => 'post_id',
                    'order'     => 'ASC'
                );  
                $loop = new WP_Query( $args );
                $banner_count = 0;
                while ( $loop->have_post() ) : $loop->the_post();

                if ( $banner_count == 0 ){
                    $active_item = 'active';
                }
                else {
                    $active_item = '';
                }
            ?>
            <li data-target="#quote-carousel" data-slide-to="<?php echo $banner_count; ?>" class="<?php echo $active_item; ?>"></li>
            <?php $banner_count++; endwhile; ?>
            </ol>



            <!-- Carousel Slides / Quotes -->


            <div class="carousel-inner">
            <?php 
                $loop = new WP_Query( $args ); 
                $banner_count = 0;
                while ( $loop->have_posts() ) : $loop->the_post();
                if ( $banner_count == 0 ){
                    $active_item = 'active';
                }
                else {
                    $active_item = '';
                }   
            ?>
                <!-- Quote 1 -->
                <div class="item <?php echo $active_item; ?>">
                    <blockquote>
                        <div class="row">
                            <div class="col-sm-3 text-center">
                            <img class="img-circle">
                            <?php 
                                if ( has_post_thumbnail() ) {
                                    the_post_thumbnail( array( 200, 100 ) );
                                }
                            ?>
                            </div>
                            <div class="col-sm-9">
                            <?php the_content(); ?>
                            <small><?php the_title(); ?></small>
                            </div>
                        </div>
                    </blockquote>
                </div>
            <?php $banner_count++; endwhile; ?>
            </div>

最佳答案

您在 have_posts() 上缺少指标的 s

while ( $loop->have_post() ) : $loop->the_post();

应该是:

while ( $loop->have_posts() ) : $loop->the_post();

我还建议将您的查询移至顶部并运行一次而不是两次。

<?php
$args = array(
    'post_type' => 'testimonial',
    'orderby'   => 'post_id',
    'order'     => 'ASC'
);  

$loop = new WP_Query( $args );

if ( $loop->have_posts() ) : ?>
    <ol class="carousel-indicators">
        . . .
        WHILE HERE FOR LIST ITEMS

    </ol>

    <?php $loop->rewind_posts(); // reset the loop and re-use ?>

    <div class="carousel-inner">
        . . .
        WHILE HERE TO LOOP THROUGH ITEMS
        . . .
    </div>

    <?php
endif;

关于php - Bootstrap 轮播指示器未在 Wordpress 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42036520/

相关文章:

php - WordPress mysql 消失了

wordpress - 如何将 ACF 图像字段添加到自定义分类的 WP 管理表列

javascript - 我可以在 Bootstrap 弹出窗口中放置一个链接吗?

css - 宽度 : 100%; height: auto dont work properly

css - 我可以在 Bootstrap 菜单中放置两个链接吗

php - 在客户订单历史记录中显示最后的 WooCommerce 管理员订单备注

php - 如何在 PHP 中使用 MySQL 按位运算?

php - 多个 MySQL 查询还是一个具有多个 JOIN 的查询?

php - Bud1%@@@@E%DSDB`@@@是什么?

php - 如何合并两个WordPress查询并随机化?