用php启动传送带 [英] Bootstrap carousel with php

查看:138
本文介绍了用php启动传送带的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I need to create dinamicly bootstrap carousel like this:
    < li data-target =#carousel-example-genericdata-slide-to =0class =active>< / li>
  1. 等...
    < / ol>

    <! - 幻灯片包装 - >
    < div class =carousel-inner>
    < div class =item active>
    < img src =someIMG.jpgalt =...>

    < / div>
    < div class =item>
    < img src =someIMG-nn.jpgalt =...>

    < / div>
    等...
    < / div>

    <! - 控件 - >
    < a class =left carousel-controlhref =#carousel-example-genericrole =buttondata-slide =prev>
    < span class =glyphicon glyphicon-chevron-left>< / span>
    < / a>
    < a class =right carousel-controlhref =#carousel-example-genericrole =buttondata-slide =next>
    < span class =glyphicon glyphicon-chevron-right>< / span>
    < / a>
    < / div>

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

现在我有一个我称之为创建自动引导轮播的php函数:

Now I have a php functions which I call to create dinamicly 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>
    **<?php $ i = 0;?> **
    **<?php while(osc_has_item_resources()){?> **
    < li data -target =#carousel-example-genericdata-slide-to =**<?php echo $ i; $ i + 1;?> **class =active>< / li> ;
    **<?php}?> **
    < / ol>

    <! - 幻灯片包装 - >
    < div class =carousel-inner>
    **<?php while(osc_has_item_resources()){?> **
    < div class =item>
    < img src =**<?php echo osc_resource_url();?> **alt =...>


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


    < / div>

    <! - 控件 - >
    < a class =left carousel-controlhref =#carousel-example-genericrole =buttondata-slide =prev>
    < span class =glyphicon glyphicon-chevron-left>< / span>
    < / a>
    < a class =right carousel-controlhref =#carousel-example-genericrole =buttondata-slide =next>
    < span class =glyphicon glyphicon-chevron-right>< / span>
    < / a>


    < / div>



我很开心,所以我不知道这里有什么可以做的。在我的逻辑中,我认为我写的很好,但是我写的不工作......两个问题或其他问题呢?

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

I'm beginer so I dont know what can be a probem here. In my logic I think that I write good but what I write dont work... Two while is the problem or something else?

推荐答案

你很近。但是,你正在使用该循环两次,可能无法正常工作。我不知道 osc_has_item_resources()对记录有什么作用。但试试这个。

解决方案

设置一个变量等于 osc_count_item_resources()中的任何变量,然后多次循环到建立轮播指标。在完成之后,使用(while osc_has_item_resources())循环并构建项目。

You're close. But you're using that loop twice and that may not work. I'm not sure what osc_has_item_resources() does with the records. But try this.

Set a variable equal to whatever is in osc_count_item_resources() and then loop that many times to build the carousel indicators. After you do that, use while( osc_has_item_resources() ) to loop through and build the items.
    <?php $ itemCount = osc_count_item_resources(); ?>
    <?php for($ i = 0; $ i <$ itemCount; $ i ++){?>
    < li data-target =#carousel-example-genericdata-slide-to =<?php echo $ i;?>类= 活性 >< /锂>
    <?php}?>
    < / ol>

    <! - 幻灯片包装 - >
    < 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>
    <! - 控件 - >
    < a class =left carousel-controlhref =#carousel-example-genericrole =buttondata-slide =prev>
    < span class =glyphicon glyphicon-chevron-left>< / span>
    < / a>
    < a class =right carousel-controlhref =#carousel-example-genericrole =buttondata-slide =next>
    < span class =glyphicon glyphicon-chevron-right>< / span>
    < / a>
    < / div>

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

这篇关于用php启动传送带的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆