2020-04-30, 16:13:03
Hi Bigin,
First of all, thanks for pointing me to the use of $key in foreach loops
I can confirm that the following code now is working:
Outputting html for galleries, sliders, banners, etc. in websites is asked for a lot
so having a foreach loop doing that in ImManager is very practical.
$my_item must be some kind of array in ImManager.
Are there other ways to loop through and output the array elements ?
This is what I have found so far:
First of all, thanks for pointing me to the use of $key in foreach loops
I can confirm that the following code now is working:
Code:
<?php
$imanager = imanager();
$itemMapper = $imanager->getItemMapper();
$itemMapper->init(4); // Category 4 holds the item pictures with 5 photos
$items = $itemMapper->items;
$my_item = $itemMapper->getItem('name= pictures');
foreach ($my_item->fields->image->fullurl as $key => $fullurl) {
$url = IM_SITE_URL.$fullurl;
$title = $my_item->fields->image->title[$key];
echo "<a href='$url' data-imagelightbox='g' data-ilb2-caption='$title'>"."\n";
echo "<img src='$url' width='100'></a>"."\n";
}
?>
Outputting html for galleries, sliders, banners, etc. in websites is asked for a lot
so having a foreach loop doing that in ImManager is very practical.
$my_item must be some kind of array in ImManager.
Are there other ways to loop through and output the array elements ?
This is what I have found so far:
Code:
<?php
echo "<br>";
echo key($my_item)."<br>"; // outputs: categoryid
echo key($my_item->fields)."<br>"; // outputs: text (this is a text field setup in category 4)
echo key($my_item->fields->image->title)."<br>"; // outputs: 0
?>