用php和bootstrap carousel显示图像 [英] Show images with php and 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>
我需要在每个循环中更改图片网址。
由 因为我不知道这个函数做的主要工作是什么(是否有任何可以传递的参数,返回什么值等),我我们会建议使用array来处理图片和网址的简单解决方案: I need to create an list of images with twitter bootstrap so I write: 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: What I need to do to change image URL on every loop. Thanks and sorry for my english. The value returned by 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和bootstrap carousel显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! osc_resource_url()$ c $返回的值(在你当前的代码中)是静态的,不受当前循环的影响。这就是所有图像都相同的原因。一种解决方案是将参数传递给此函数。
<?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}?>
<?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(); ?>);"> </a>
</div><?php } ?>
<!---->
</div>
<?php } ?>
<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.);"> </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.);"> </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.);"> </a>
</div> <!---->
</div>
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. <?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']; ?>);"> </a>
</div>
<?php } ?>