dp518158 2014-10-19 22:56
浏览 52
已采纳

用php和bootstrap轮播显示图像

I need to create an list of images with twitter bootstrap so I write:

<?php osc_run_hook('item_detail', osc_item() ) ; ?>
<?php if( osc_images_enabled_at_items() && (osc_count_item_resources() > 0) ) { ?>
<div class="row hidden-xs" id="mediaCarouselThumbs" style="padding: 15px;">
    <?php $itemCount = osc_count_item_resources(); ?>
<?php for($i = 0; $i < $itemCount; $i++) { ?>
                                                    <div class="pull-left" style="width: 11.11%;">
                                <a href="#" data-target="#mediaCarousel" data-slide-to="<?php echo $i;$i+1;?>" class="thumbnail" style="background-image: url(<?php echo osc_resource_url(); ?>);">&nbsp;</a>
                            </div><?php } ?>
                            <!---->

                                            </div>
        <?php } ?>

All is fine but echo osc_resource_url(); dont give me the right url and dont change it in the loop, also with $i is everything fine and work well... So after raun this code I get:

<div class="row hidden-xs" id="mediaCarouselThumbs" style="padding: 15px;">
                                                        <div class="pull-left" style="width: 11.11%;">
                                <a href="#" data-target="#mediaCarousel" data-slide-to="0" class="thumbnail" style="background-image: url(http://dive.agroagro.com/0.);">&nbsp;</a>
                            </div>                                                    <div class="pull-left" style="width: 11.11%;">
                                <a href="#" data-target="#mediaCarousel" data-slide-to="1" class="thumbnail" style="background-image: url(http://dive.agroagro.com/0.);">&nbsp;</a>
                            </div>                                                    <div class="pull-left" style="width: 11.11%;">
                                <a href="#" data-target="#mediaCarousel" data-slide-to="2" class="thumbnail" style="background-image: url(http://dive.agroagro.com/0.);">&nbsp;</a>
                            </div>                            <!---->

                                            </div>

What I need to do to change image URL on every loop. Thanks and sorry for my english.

  • 写回答

1条回答 默认 最新

  • dongwu8050 2014-10-20 01:13
    关注

    The value returned by osc_resource_url() (in your current code) is "static" and is not affected by the current loop. This is the reason why all images are the same. One solution is to pass an argument to this function.

    Because I have no idea what is the main job that this function do (are there any arguments that can be passed, what value will be returned, etc.), I'll suggest simple solution using array for images and urls:

    <?php
        $itemCount = osc_count_item_resources();
        $images = array(
            array('url' => '#', 'image' => 'http://dive.agroagro.com/0.jpg'),
            array('url' => '#', 'image' => 'http://dive.agroagro.com/1.jpg'),
            array('url' => '#', 'image' => 'http://dive.agroagro.com/2.jpg'),
            array('url' => '#', 'image' => 'http://dive.agroagro.com/3.jpg')
        );
    ?>
    
        <?php for($i = 0; $i < $itemCount; $i++) { ?>
            <div class="pull-left" style="width: 11.11%;">
                <a href="<?php echo $images[$i]['url']; ?>" data-target="#mediaCarousel" data-slide-to="<?php echo $i;?>" class="thumbnail" style="background-image: url(<?php echo $images[$i]['image']; ?>);">&nbsp;</a>
            </div>
        <?php } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用