Jump to content

Recommended Posts

Posted

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>   
Posted

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.

Posted

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 :)

Posted

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.

Posted

You can use module Image Extra or the pro field Matrix Repeater or Table field. Or page table, but that's not so comfortable.

  • Like 1
Posted

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 ?

Posted

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) {

Posted

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
Posted

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.

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
  • Recently Browsing   0 members

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