Jump to content

Recommended Posts

Posted

Hi there,

I want get all images from an other page. I tryed this:

 $image = $pages->get("/leistungen/dekoration/")->imageK1->url;
      foreach($image as $image) {

       // Only a simple echo to test if something happend:
    	echo $image;
    }

But nothing happends?!

Posted
 $image = $pages->get("/leistungen/dekoration/")->imageK1->url;
      foreach($images as $image) {
    	echo $image->url;
    }

This do not work too. So I need a little help please.

Posted

Make sure the image field is called imageK1. If so, this should work:

foreach($pages->get("/leistungen/dekoration/")->imageK1 as $image) {
    echo "<img src='{$image->url}'>";
}
  • Like 1
Posted

  Yeah, I saw this doc. But it says nothing about accessing fields in other pages. From this doc I figured out the code above. But it do not work.

Your code seem not to make any sense.

1) Please can you explain to me what the variable $image in the first line should hold. (and what it actually holds)

2) and what do you want to do with a loop in the second line? (and where does $images come from?)

You should go step by step. FIrst you should inspect the first line of code. If this does what you expect / want, go on with the next step.

:-X  And really, you should _read_ the doc kongondo has you pointed to, once or twice more.

  • Like 1
Posted

The two examples you posted won't work because you are using $image in both instances and not $images and then $image. You were also getting the url, rather than just the imageK1 field in your initial line.

What Mats posted will work, but if it makes more sense to you, you can adjust what you wrote to:

$images = $pages->get("/leistungen/dekoration/")->imageK1;
foreach($images as $image) {
    echo $image->url;
}
 

and it should work fine.

What you are doing is assigning all the images in the imageK1 field on the /leistungen/dekoration/ page to the array $images. Then you want to iterate through this, making each item $image and echo it out.

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