sendxt Posted June 9, 2014 Share Posted June 9, 2014 Hi there;) I have problem with images repeater, i can't return him with to the cycle. I do it so: <?php foreach($page->img as $k) { $small = $k->small_img->first(); $big = $k->big_img->first(); echo '<div class="break">'; echo '<a class="fancybox-thumb" id="frame-4" rel="fancybox-thumb" href="'.$big->url.'" title="">; echo '<img class="img-4" src="'.$small->url.'" alt=""></a>'; echo '</div>'; } ?> foreach return me only one field from array , but I know that there are more, how me return all elements from img ? Link to comment Share on other sites More sharing options...
kongondo Posted June 9, 2014 Share Posted June 9, 2014 (edited) Hi Sendxt, Welcome to ProcessWire and the Forums! I am in a bit of a hurry. See solution here..https://processwire.com/talk/topic/6243-images-in-a-repeater-field/ Key thing to remember is that behind the scenes repeaters are also pages and need to be treated as such...hence you may also need to foreach (loop) through them....Normally, this would require nested foreachs...if the images are also an array.. foreach ($page->my_repeater_field as $f) //$f is the repeater....you need to loop through it if you have multiple images inside it... foreach ($f->images as $image)//do stuff.... Edited June 9, 2014 by kongondo 1 Link to comment Share on other sites More sharing options...
sendxt Posted June 9, 2014 Author Share Posted June 9, 2014 Hi Sendxt, Welcome to ProcessWire and the Forums! I am in a bit of a hurry. See solution here..https://processwire.com/talk/topic/6243-images-in-a-repeater-field/ Key thing to remember is that behind the scenes repeaters are also pages and need to be treated as such...hence you may also need to foreach (loop) through them....Normally, this would require nested foreachs...if the images are also an array.. foreach ($page->my_repeater_field as $f) //$f is the repeater....you need to loop through it if you have multiple images inside it... foreach ($f->images as $image)//do stuff.... but i can't make foreach ( $f->images as $image ) // because in my repeater field -> two fields for big_img and small_img (( Or need to do one field and put there small and big img ? Link to comment Share on other sites More sharing options...
sendxt Posted June 9, 2014 Author Share Posted June 9, 2014 I did so with text, was good. foreach($page->product_name as $field) { echo '<p class="name">'.$field->sub_name.'</p>'; echo '<p class="service">'.$field->sub_text.'</p></td>'; } with picture so can not be done? Link to comment Share on other sites More sharing options...
sendxt Posted June 10, 2014 Author Share Posted June 10, 2014 foreach($page->img as $k) { foreach($k->small_img as $image) { echo '<div class="break">'; echo '<a class="fancybox-thumb" id="frame-4" rel="fancybox-thumb" href="'.$image->url.'" title="">'; echo '<img class="img-4" src="'.$image->url.'" alt=""></a>'; echo '</div>'; } } work like this, but how to do with foreach two field ? http://prntscr.com/3rdho9 Link to comment Share on other sites More sharing options...
Ole Posted June 11, 2014 Share Posted June 11, 2014 I don't get your approach completely.Do you want to link with a thumbnail a bigger version of the same image? Link to comment Share on other sites More sharing options...
Webrocker Posted June 29, 2014 Share Posted June 29, 2014 Hi, I'm fairly new to PW myself, but I think you need to output it like this, assuming your structure is: - page with images -- images (repeater field) --- small_image (image field) --- big_image (image field) -- other content (textarea) -- (...) $images_to_show = $page->images // herein are all image repeater instances of the current page foreach( $images_to_show as $imgs) { // now we are "in" one repeater, so we need to get the repeater's fields foreach( $imgs as $img) { // do whatever you want with the fields echo $img->small_image->url; echo $img->big_image->url; } } I coded this in the browser, not tested, but I think you're missing the loop "inside" the repeater to get to the fields you want. Link to comment Share on other sites More sharing options...
Webrocker Posted June 29, 2014 Share Posted June 29, 2014 uhm, If the only reason you use the "images" as a repeater field is to get different sizes of the same image, you have other options:If you want to control the size and aspect ration of the different sizes, but allow your editor the control of the part of the image to be shown, have a look at the fieldtypeCropImage module set http://modules.processwire.com/modules/fieldtype-crop-image/. If you just want to use different sizes/scales of the image, you can simply make them on the fly in your output; see "resizing images" here: http://processwire.com/api/fieldtypes/images/ Structure w/o repeater field: - page with images -- images (image field) -- other content (textarea) -- (...) $images_to_show = $page->images foreach( $images_to_show as $img){ $large = $image->width(500); $thumb = $image->size(100, 100); echo '<a href="' . $large->url . '"><img src="' . $thumb ->url . '" /></a>'; } Tom Link to comment Share on other sites More sharing options...
Reezal AQ Posted March 5, 2017 Share Posted March 5, 2017 Hello, I'm trying to call images in repeater to appear in a slideshow, can somebody tell me what's wrong with this code ? I have no problem calling H1 & paragraph. <div class="carousel-inner" role="listbox"> <? foreach($page->SlideImagesRepeater as $SlideImagesRepeat): ?> <div class="item active"> <img src="<?=$SlideImagesRepeat->Sliders->images->url?>" alt="Hero Slide"> <div class="carousel-caption"> <h1><?=$SlideImagesRepeat->SlideTitle ?></h1> <p><?=$SlideImagesRepeat->SlideParagraph ?></p> </div> </div> <? endforeach; ?> </div> Thanks Link to comment Share on other sites More sharing options...
fbg13 Posted March 5, 2017 Share Posted March 5, 2017 1 hour ago, Reezal AQ said: <img src="<?=$SlideImagesRepeat->Sliders->images->url?>" alt="Hero Slide"> @Reezal AQ try $SlideImagesRepeat->Sliders->first()->url Link to comment Share on other sites More sharing options...
Reezal AQ Posted March 5, 2017 Share Posted March 5, 2017 2 minutes ago, fbg13 said: @Reezal AQ try $SlideImagesRepeat->Sliders->first()->url Sorry it didn't work, page failed to load. Link to comment Share on other sites More sharing options...
Reezal AQ Posted March 5, 2017 Share Posted March 5, 2017 Ok, my bad. The correct codes are : <div class="carousel-inner" role="listbox"> <? foreach($page->SlideImagesRepeater as $SlideImagesRepeat): ?> <div class="item active"> <img src="<?=$SlideImagesRepeat->SlideshowImage->first()->url?>" alt="Hero Slide"> <div class="carousel-caption"> <h1><?=$SlideImagesRepeat->SlideTitle ?></h1> <p><?=$SlideImagesRepeat->SlideParagraph ?></p> </div> </div> <? endforeach; ?> </div> but there's another problem. There are 3 slides on the homepage, the first one has <div class="item active"> while the other 2 slides don't have any <div class="item">. Because the class active gets repeated 3 time all slides appearing at once. How do you fix this ? Link to comment Share on other sites More sharing options...
fbg13 Posted March 5, 2017 Share Posted March 5, 2017 <?php $x = 0; foreach($page->SlideImagesRepeater as $SlideImagesRepeat) : $class = ($x === 0) ? "active" : ""; ?> <div class="item <?= $class ?>"> rest of code </div> <?php $x++; endforeach; ?> http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary 2 Link to comment Share on other sites More sharing options...
Reezal AQ Posted March 5, 2017 Share Posted March 5, 2017 3 minutes ago, fbg13 said: <?php $x = 0; foreach($page->SlideImagesRepeater as $SlideImagesRepeat) : $class = ($x === 0) ? "active" : ""; ?> <div class="item <?= $class ?>"> rest of code </div> <?php $x++; endforeach; ?> http://php.net/manual/ro/language.operators.comparison.php#language.operators.comparison.ternary Thanks! it works. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now