好吧,所以这就是我想要实现的!试图创建只有一个foreach元素的灯箱gallery
我有一个PHP脚本,我从API/JSON设置中将信息导入到foreach()语句中。
这是我的一些代码:
$ch = curl_init();
$category=$_GET['category'];
$url="http://www.someurl.com/api/listings?token=f716909f5d644fe3702be5c7895aa34e&group_id=10046&species=".$category;
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'X-some-API-Key: f716909f5d644fe3702be5c7895aa34e',
));
$json = json_decode(curl_exec($ch), true);
// Functions relating to the Echo Code
foreach($json['listings'] as $listing)
{
$short_personality=substr($listing['personality'],0,500);
$peturl="http://www.someurl.com/?variable=".$listing['id'];
$medium_photo=$listing['photos'][0]['large_340'];
$gender_class=strtolower($listing['gender']);
$breed_class=strtolower($listing['species']);
$name=($listing['name']);
然后,我创建的图像与下面的代码显示:
// Echo the output
echo'<div class="animal">
<div class="animal-image">';
if ($listing['photos'] > 1) {
echo '<a class="size-thumbnail thickbox" rel="gallery" href="'.$medium_photo.'">
<img src="'.$medium_photo.'" class="image-with-border" alt="">
<div class="border" style="width: 340px; height: 340px;">
<div class="open"></div>
</div>
</a>';
}
else {
echo '<a class="size-thumbnail thickbox" href="'.$medium_photo.'">
<img src="'.$medium_photo.'" class="image-with-border" alt="">
<div class="border" style="width: 340px; height: 340px;">
<div class="open"></div>
</div>
</a>';
}
因此,例如,在API中25拉所有项目都格式化为各自的部分,每部分都有自己的初始照片。当我点击那张照片时,灯箱会加载。
但是,它加载了API调用中的所有图像的灯箱,所以我得到了在灯箱中可用的144个图像。
有没有办法限制每个正在检索的项目在灯箱中的照片?
任何帮助,将不胜感激。
通过说*它加载在API调用中的所有图像的灯箱,所以我得到144图像可用在灯箱*你的意思当你用鼠标旋转轮子或按下箭头键时,你正在查看下一个,就像所有的图像都在一个画廊中一样? – Sharky
正确sharky! –
插件的名称是什么? ThickBox的? – Sharky