Jump to content

Roderick

Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by Roderick

  1. Tom's suggestion works, thanks. It's a bit confusing to me to see people using either curly brackets or a colon when calling foreach, but I guess it's up to the user to choose their preferred method.
  2. I'm trying to add a class and <div> tags to part of an array. It's an array of different fields (images and text) from a number of child pages. I want the result of each child to be styled individually, but so far, I've only been able to style the whole array or each individual item. I tried: <div class="my-class"> <?php foreach($page->children as $child): foreach($child->images as $image): echo "<img src='$image->url'/>"; endforeach; endforeach; ?> </div> which adds a class to the whole array. Or: <?php foreach($page->children as $child): foreach($child->images as $image): echo "<div class='my-class'> <img src='$image->url'/></div>"; endforeach; endforeach; ?> which adds a class to each individual field. I understand that I have to add something to the code that divides the array for each child page, but how?
  3. Thanks @diogo. I see my mistakes now. Can you explain what you mean when you say 'just use brackets'? I'm new to all this.
  4. I'm unable to get an array of all image url's when calling the underneath, even though several children contain multiple images. I only get the first image url of each child. Am I writing something wrong here? <?php foreach($page->children as $child): foreach($child->images as $image); echo $image->url; endforeach; ?> All image url's display fine on the child page itself when calling: <?php foreach($page->images as $image): echo $image->url; endforeach; ?>
  5. @kongondo sorry, yes. Will do.
  6. hello, stuck again on something that is probably quite simple for experienced users. I am creating an array of images from all children of a parent that should be styled per child, so the output would be something like this: <div class="style-1"> <img src="/site/assets/files/1016/img1.jpg> <img src="/site/assets/files/1016/img2.jpg> </div> <div class="style-2"> <img src="/site/assets/files/1020/img1.jpg> <img src="/site/assets/files/1020/img2.jpg> </div> // et cetera So far, I've only been able to either style each individual image or style them all at once..
  7. Thanks Tom, that did the trick. Still a lot to learn
  8. Hi I'm an inexperienced editor, but eager to learn more about ProcessWire. I've created a simple script that echoes the bodies of a parent's children. <?php foreach ($page->children as $child): echo ("<div class='my-class'> $child->body"); endforeach; ?> My question is how do I get these bodies to be styled individually?
×
×
  • Create New...