我需要像这样创建动态bootstrap轮播:
<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函数,我调用它来创建动态bootstrap carousel:
**<?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>
我是初学者,所以我不知道这里有什么问题。在我的逻辑中,我认为我写得很好,但我写的不是工作......两个问题还是其他什么?
请帮忙,抱歉我的英语。谢谢!
答案 0 :(得分: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>
答案 1 :(得分:0)
对于botstrap4可以与替换一起使用
<div class="carousel-item <?php echo ($i === 0) ? ' active': ''; ?>">
<img src="<?php echo osc_resource_url(); ?>" alt="...">
</div>