pwired Posted May 15, 2016 Share Posted May 15, 2016 Hi,I have this for each loop to output pictures from a page and works perfectly. However each picture gets two lines of text overlayed and these two lines oftext for each picture are stored in the page as $text1 and $text2, see below.How do I make $text1 and $text2 make part of the for each loop so they willbe outputted in the code below ? <div class="photo-gallery"> <?php if(count($page->images)) { echo "<ul id='gallery' class='list-unstyled row'>"; foreach($page->images as $image) { $large = $image->width(700); $thumb = $image->size(100, 100); echo "<li class=" . '""' . "data-responsive=" . '""' . "data-src=" . $large->url . " data-sub-html=" . '"' . "<h4>" . $text1 . "</h4>" . "<p>" . $text2 . "</p>" . '"' . ">"; echo "<a href=" . '""' . ">"; echo "<img class=" . '"img-responsive"' . "src=" . $thumb->url . ">"; echo "</a>"; echo "</li>"; } echo "</ul>"; } ?> </div> Link to comment Share on other sites More sharing options...
adrian Posted May 15, 2016 Share Posted May 15, 2016 Are $text1 and $text2 fields on the same page as the images field? So they are the same text for each image? It sounds like what you want is $page->text1, but until we know exactly where $text1 and $text2 are coming from, it's hard to know. Link to comment Share on other sites More sharing options...
tpr Posted May 15, 2016 Share Posted May 15, 2016 Brain fart? Get the strings before the loop and there you go $text1 = $page->text1; Or are these texts not on the same page? F***, didn't know adrian was also online Link to comment Share on other sites More sharing options...
pwired Posted May 15, 2016 Author Share Posted May 15, 2016 Yes you guys are right, I can't use $text1 and $text2 on the page where also the pictures are stored or every picture will get the same text as overlay. I need two lines with different text for every picture. Link to comment Share on other sites More sharing options...
tpr Posted May 15, 2016 Share Posted May 15, 2016 You can use module Image Extra or the pro field Matrix Repeater or Table field. Or page table, but that's not so comfortable. 1 Link to comment Share on other sites More sharing options...
pwired Posted May 15, 2016 Author Share Posted May 15, 2016 I see that each picture in the page already has a text field underneath it. How can I use that field in the for each loop ? Link to comment Share on other sites More sharing options...
tpr Posted May 15, 2016 Share Posted May 15, 2016 $image->description But since you wrote 2 text fields, not one, it's not really an alternative. And the description field is for... well, for image description I would use Image Extra, or the other profields mentioned above. http://modules.processwire.com/modules/image-extra/ 1 Link to comment Share on other sites More sharing options...
pwired Posted May 15, 2016 Author Share Posted May 15, 2016 Thanks tpr, but how would I make description make part of the for each loop, something like this ?? foreach($page->images as $image) ($page->description as $text) { Link to comment Share on other sites More sharing options...
tpr Posted May 15, 2016 Share Posted May 15, 2016 No, there is only one field per image: foreach($page->images as $image) { echo '<img src="' . $image->width(200,0)->url . '">'; echo '<p>' . $image->description . '</p>'; } 2 Link to comment Share on other sites More sharing options...
pwired Posted May 15, 2016 Author Share Posted May 15, 2016 Ok guys thanks for the replies, I have one line of caption text now working: foreach($page->images as $image) { $large = $image->width(700); $thumb = $image->size(100, 100); $text = $image->description; I leave the second caption text line for later. 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