0

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

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

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

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

4

2 回答 2

2

你很近。但是您使用该循环两次,这可能行不通。我不确定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>
于 2014-10-17T19:32:31.813 回答
0

对于 botstrap4 与替换一起使用

<div class="carousel-item <?php echo ($i === 0) ? ' active': ''; ?>">
  <img src="<?php echo osc_resource_url(); ?>" alt="...">
</div>
于 2019-04-04T09:20:56.157 回答