首页 > 解决方案 > Wordpress Post Carousel - 如何自动填充?

问题描述

网站内滑块的图像我正在创建一个网站,我希望最新帖子在导航栏下方的页面顶部轮播。我使用 Bootstrap 作为主题,使用 Owl-carousel 作为轮播本身,使用 Wordpress 作为帖子等。在以这种方式使用 Wordpress 时,我仍然是一个新手,希望能得到一些帮助!

我已经尝试使用填充轮播,<?php if (have_posts()) : while (have_posts()) : the_post(); ?>并且我认为它创建 3 个单独的轮播而不是填充第一个的原因是因为这个,但我不确定如何修复它。

<div class="container">

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <div class="owl-carousel owl-theme">
                <div class="item">
                    <div class="card" style="width: 18rem;">
                        <img class="card-img-top" src=".../100px180/" alt="Card image cap">
                        <div class="card-body">
                            <h5 class="card-title"><?php the_title(); ?></h5>
                            <p class="card-text"><?php the_excerpt(); ?></p>
                            <a href="<?php the_permalink(); ?>" class="btn btn-success"> Read More</a>
                        </div>
                    </div>
                </div>
            </div>
        <?php endwhile;
    endif; ?>
</div>

我需要它,而不是创建 3 个单独的轮播,而是用 Wordpress 的最新帖子填充一个。非常感谢所有帮助!

标签: phpjqueryhtmlwordpressowl-carousel

解决方案


@Scuzzy 回答了问题,现在已修复。while 循环处于错误的级别。谢谢您的帮助。


推荐阅读