用php和bootstrap carousel显示图像 [英] Show images with php and bootstrap carousel

查看:108
本文介绍了用php和bootstrap carousel显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用twitter bootstrap创建图像列表,所以我写道:

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

< / div>
<?php}?>

一切正常,但回声osc_resource_url();不要给我正确的网址,不要在循环中改变它,也与$我是一切正常,工作得很好...所以后拉这个代码我得到:

 < div class =row hidden-xsid =mediaCarouselThumbsstyle =padding:15px;> 
< div class =pull-leftstyle =width:11.11%;>
< / div> < div class =pull-leftstyle =width:11.11%;>
< / div> < div class =pull-leftstyle =width:11.11%;>
< / div> <!---->

< / div>

我需要在每个循环中更改图片网址。

解决方案

osc_resource_url()

因为我不知道这个函数做的主要工作是什么(是否有任何可以传递的参数,返回什么值等),我我们会建议使用array来处理图片和网址的简单解决方案:

 <?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-leftstyle =width:11.11%;>
< a href =<?php echo $ images [$ i] ['url'];?> data-target =#mediaCarouseldata-slide-to =<?php echo $ i;?> class =thumbnailstyle =background-image:url(<?php echo $ images [$ i] ['image'];?>);>& nbsp;< / a>
< / div>
<?php}?>


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.

解决方案

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

这篇关于用php和bootstrap carousel显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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