justnew77 Posted January 20, 2014 Share Posted January 20, 2014 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?! Link to comment Share on other sites More sharing options...
kongondo Posted January 20, 2014 Share Posted January 20, 2014 http://processwire.com/api/fieldtypes/images/ 1 Link to comment Share on other sites More sharing options...
justnew77 Posted January 20, 2014 Author Share Posted January 20, 2014 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. Link to comment Share on other sites More sharing options...
justnew77 Posted January 20, 2014 Author Share Posted January 20, 2014 $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. Link to comment Share on other sites More sharing options...
Mats Posted January 20, 2014 Share Posted January 20, 2014 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}'>"; } 1 Link to comment Share on other sites More sharing options...
horst Posted January 20, 2014 Share Posted January 20, 2014 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. And really, you should _read_ the doc kongondo has you pointed to, once or twice more. 1 Link to comment Share on other sites More sharing options...
adrian Posted January 20, 2014 Share Posted January 20, 2014 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. 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