【问题标题】:Several Bootstrap Carousels using PHP to fetch files几个使用 PHP 获取文件的 Bootstrap Carousels
【发布时间】:2020-04-06 18:19:43
【问题描述】:

我正在尝试使用参数和 Bootstrap 构建几个轮播,为了避免重复代码,我使用变量 $i 来获取图像。问题是每个文件夹都有不同数量的图像。使用 ($i=1; $i

这是我的代码:

<div id="carouselExampleControls" class="carousel slide" data-ride="carousel" data-interval="false">
    <div class="carousel-inner">
        <?php
            for ($i=1; $i <= 30; $i++) {
                if ($i==1) {
                        print '<div class="carousel-item active"><img class="d-block w-100 img-fluid" src="img/project_'.$project.'/slider_'.$i.'.jpg" alt="project slider"></div>';
                }
                else {
                    print '<div class="carousel-item"><img class="d-block w-100 img-fluid" src="img/project_'.$project.'/slider_'.$i.'.jpg" alt="projectslider"></div>';
                }
            }
        ?>
    </div>
    <a class="carousel-control-prev carousel-project-prev" href="#carouselExampleControls" role="button" data-slide="prev">
        <span class="sr-only">Previous</span>
    </a>
    <a class="carousel-control-next carousel-project-next" href="#carouselExampleControls" role="button" data-slide="next">
        <span class="sr-only">Next</span>
    </a>
</div>

【问题讨论】:

    标签: php html bootstrap-carousel


    【解决方案1】:

    你是先在这里搜索的吗?

    List all files in one directory PHP 是一个潜在的答案,您可以使用它并获取文件列表,将它们添加到数组中,然后将count($array); 作为总数,或者更好地在该数组中使用foreach显示它们中的每一个。

    【讨论】:

      猜你喜欢
      • 2019-09-11
      • 2015-04-29
      • 1970-01-01
      • 2011-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-07
      相关资源
      最近更新 更多