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 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式