Jump to content

Recommended Posts

Posted

Hello ppl

I'm trying to create an image banner to show in all pages of the site, and for this i created a page to hold multiple images in a field (latter im gonna deal with animating them). The page is published, So this is the tree of values i got:

banners_slideshow.jpg

i can address the page with

$pg_settings = $pages->get('name=settings');

it seem to be correct because print_r gets me a biiiig array if info

now the problem is getting the array of images, with their respective url's. I tried:

$pg_settings = $pages->get('name=settings');
// echo "<br />pg_settings: " . print_r($pg_settings->get("banners_slideshow")); // seems ok...

$imgs = $pg_settings->get("banners_slideshow");
print_r($imgs[0]->get("url")); // i got nothing??

In this page i also have a non repeatable image field for the logo, so i think i cant use the images array from that page. 

the question remains: how do i address a field with multiples images, that is in another page?

thanks for the patience!

Posted

i also dont get why both print_r's show the same result 

$pg_settings = $pages->get('name=settings')
print_r($pg_settings);

$imgs = $pg_settings->get("banners_slideshow");
print_r($imgs[0]->get("url"));
Posted

If you access the field you get a WireArray of image objects, and each has a method url (I think), it's not a property or a field.

$imgs = $pg_settings->get("banners_slideshow");
$imgs->first()->url; // the first
$imgs[0]->url; 
$img->eq(0)->url; // etc

foreach($imgs as $img) echo $img->url;

Forget about print_r() on arrays and object, you won't get useful infos most of the time it's overkill.


Maybe have a deep read here http://processwire.com/api/fieldtypes/images/

  • Like 2

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
×
×
  • Create New...