2020-04-30, 06:08:28
Hi,
I want to select an item that holds 5 photos
Then I want to do a for each loop to store from the image field the fullurl and title in the variables $url and $title
that I can use to echo html.
Is it possible to do this with only 1 for each loop ?
The following for each loop does not put the fullurl and title in the variables:
How can I do this with one for each loop ?
Do I need to use a separate for-each loop to get each field property ?
I want to select an item that holds 5 photos
Then I want to do a for each loop to store from the image field the fullurl and title in the variables $url and $title
that I can use to echo html.
Is it possible to do this with only 1 for each loop ?
The following for each loop does not put the fullurl and title in the variables:
Code:
$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 as $picture) {
$url = $picture->fullurl;
$title = $picture->title;
echo "<a href=" . '"' . IM_SITE_URL . $url . '"' . " data-imagelightbox=" . '"g"' . " data-ilb2-caption=" . $title . ">" . "\n";
echo "<img src=" . '"' . IM_SITE_URL . $url . '"' . " width=" . '"100"' . ">" . "</a>" . "\n";
}
How can I do this with one for each loop ?
Do I need to use a separate for-each loop to get each field property ?