【问题标题】:Bootstrap carousel with OS-Class带有 OS-Class 的引导轮播
【发布时间】:2014-10-17 19:25:18
【问题描述】:

我需要像这样创建动态引导轮播:

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
    <li data-target="#carousel-example-generic" data-slide-to="1"></li>
    etc...
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner">
    <div class="item active">
      <img src="someIMG.jpg" alt="...">

    </div>
    <div class="item">
      <img src="someIMG-nn.jpg" alt="...">

    </div>
    etc...
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
  </a>
</div>

现在我有一个 osclass 函数,我调用它来创建动态引导轮播:

**<?php osc_run_hook('item_detail', osc_item() ) ; ?>
                    <?php if( osc_images_enabled_at_items() && (osc_count_item_resources() > 0) ) { ?>**

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
**<?php $i=0;?>**
                            **<?php while( osc_has_item_resources() ) { ?>**
    <li data-target="#carousel-example-generic" data-slide-to="**<?php echo $i; $i+1;?>**" class="active"></li>
    **<?php } ?>** 
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner">
**<?php while( osc_has_item_resources() ) { ?>**
    <div class="item">
      <img src="**<?php echo osc_resource_url(); ?>**" alt="...">


    </div>
    **<?php } ?>** 


  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
  </a>


</div>

我是初学者,所以我不知道这里有什么问题。在我的逻辑中,我认为我写得很好,但我写的东西不起作用......两个while是问题还是其他什么?

请帮忙,对不起我的英语。谢谢!

【问题讨论】:

  • 只是我试图包含使用 twitter bootstrap carousel 动态创建 HTML 的功能,但效果不佳......
  • 如果有人来这里寻求答案,osc_has_item_resources() 不能在不重置查询的情况下使用两次。在第一次循环后尝试osc_reset_items()

标签: twitter-bootstrap twitter-bootstrap-3 osclass


【解决方案1】:

你已经接近了。但是您使用该循环两次,这可能行不通。我不确定osc_has_item_resources() 对这些记录做了什么。但是试试这个。

设置一个等于osc_count_item_resources() 的变量,然后循环多次以构建轮播指示器。完成后,使用while( osc_has_item_resources() ) 循环并构建项目。

<?php osc_run_hook('item_detail', osc_item() ) ; ?>
<?php if( osc_images_enabled_at_items() && (osc_count_item_resources() > 0) ) { ?>

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
<?php $itemCount = osc_count_item_resources(); ?>
<?php for($i = 0; $i < $itemCount; $i++) { ?>
    <li data-target="#carousel-example-generic" data-slide-to="<?php echo $i; ?>" class="active"></li>
<?php } ?>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner">
<?php $i = 0; ?>
<?php while( osc_has_item_resources() ) { ?>
    <div class="item<?php echo ($i === 0) ? ' active': ''; ?>">
      <img src="<?php echo osc_resource_url(); ?>" alt="...">
    </div>
<?php $i++; ?>
    <?php } ?>
  </div>
  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
  </a>
</div>

【讨论】:

  • 没关系,谢谢,但是当我编写相同的代码时,html 可以正常工作,但是这是动态创建的然后不能正常工作...在两种情况下代码是相同的...
  • 这是我得到的:jsfiddle.net/gy6we7xt 但我不知道为什么隐藏?
  • 现在我知道是什么问题了。第一个 class=item 必须是 class="item active" ...我该怎么做?
  • 我更新了代码。我检查它是否是循环中第一个回显活动的。 &lt;li data-target="#carousel-example-generic" data-slide-to="&lt;?php echo $i; ?&gt;" class="active&lt;?php echo ($i === 0) ? 'active': ''; ?&gt;"&gt;&lt;/li&gt;。在不需要之前,该 LI 标记中还有一个点从您的代码中增加了 $i。我删除了。
  • 现在,所有课程都处于活动状态......所以不要再工作了
【解决方案2】:

对于 botstrap4 与替换一起使用

<div class="carousel-item <?php echo ($i === 0) ? ' active': ''; ?>">
  <img src="<?php echo osc_resource_url(); ?>" alt="...">
</div>

【讨论】:

    猜你喜欢
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 2016-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    相关资源
    最近更新 更多