Jump to content

include $text in image for each loop


pwired
 Share

Recommended Posts

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 of
text 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 will
be 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

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

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

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

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>';
}
  • Like 2
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...